From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2062) id E72E23856944; Wed, 5 Jul 2023 22:04:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E72E23856944 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1688594696; bh=pJtZr/f5W8D79s9pPoW/KrMxNR/iOjwdSbf5e60qoM4=; h=From:To:Subject:Date:From; b=Yit4E+DuED15gkPK0axNfFWfgqygSPcAdkb2uFIcgU9xVe7+YdvjCWV+FTD2oEZuJ Lfi5yoBHOZUhb4EEacXZLUykmzOHrKhJqRQRm35a/O19V/zyYIFm3ajYSKZWv8dEvE AHD6VUmVMqvcekA2+wVumyefMP0A7ojTVElbO42g= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Thomas Rodgers To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r14-2328] libstdc++: Split up pstl/set.cc testcase X-Act-Checkin: gcc X-Git-Author: Thomas Rodgers X-Git-Refname: refs/heads/master X-Git-Oldrev: be240fc6acc9714e66afbfbe6dc193844bfcba05 X-Git-Newrev: acfe8fa8dc4907e8fe7b878654112c397d6d59c3 Message-Id: <20230705220456.E72E23856944@sourceware.org> Date: Wed, 5 Jul 2023 22:04:56 +0000 (GMT) List-Id: https://gcc.gnu.org/g:acfe8fa8dc4907e8fe7b878654112c397d6d59c3 commit r14-2328-gacfe8fa8dc4907e8fe7b878654112c397d6d59c3 Author: Thomas Rodgers Date: Wed Jul 5 14:13:02 2023 -0700 libstdc++: Split up pstl/set.cc testcase This testcase is causing some timeout issues. This patch splits the testcase up by individual set algorithm. libstdc++-v3:/ChangeLog: * testsuite/25_algorithms/pstl/alg_sorting/set.cc: Delete file. * testsuite/25_algorithms/pstl/alg_sorting/set_difference.cc: New file. * testsuite/25_algorithms/pstl/alg_sorting/set_intersection.cc: Likewise. * testsuite/25_algorithms/pstl/alg_sorting/set_symmetric_difference.cc: Likewise. * testsuite/25_algorithms/pstl/alg_sorting/set_union.cc: Likewise. * testsuite/25_algorithms/pstl/alg_sorting/set_util.h: Likewise. Diff: --- .../25_algorithms/pstl/alg_sorting/set.cc | 289 --------------------- .../pstl/alg_sorting/set_difference.cc | 93 +++++++ .../pstl/alg_sorting/set_intersection.cc | 94 +++++++ .../pstl/alg_sorting/set_symmetric_difference.cc | 95 +++++++ .../25_algorithms/pstl/alg_sorting/set_union.cc | 93 +++++++ .../25_algorithms/pstl/alg_sorting/set_util.h | 76 ++++++ 6 files changed, 451 insertions(+), 289 deletions(-) diff --git a/libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set.cc b/libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set.cc deleted file mode 100644 index 0343739dfd1..00000000000 --- a/libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set.cc +++ /dev/null @@ -1,289 +0,0 @@ -// -*- C++ -*- -// { dg-options "-ltbb" } -// { dg-do run { target c++17 } } -// { dg-timeout-factor 3 } -// { dg-require-effective-target tbb_backend } - -//===-- set.pass.cpp ------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include "pstl/pstl_test_config.h" - -#ifdef PSTL_STANDALONE_TESTS - -#include -#include - -#include "pstl/execution" -#include "pstl/algorithm" -#else -#include -#include -#endif // PSTL_STANDALONE_TESTS - -#include "pstl/test_utils.h" - -using namespace TestUtils; - -template -struct Num -{ - T val; - - Num() : val{} {} - Num(const T& v) : val(v) {} - - //for "includes" checks - template - bool - operator<(const Num& v1) const - { - return val < v1.val; - } - - //The types Type1 and Type2 must be such that an object of type InputIt can be dereferenced and then implicitly converted to both of them - template - operator Num() const - { - return Num((T1)val); - } - - friend bool - operator==(const Num& v1, const Num& v2) - { - return v1.val == v2.val; - } -}; - -template -struct test_set_union -{ - template - typename std::enable_if::value, void>::type - operator()(Policy&& exec, InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, - Compare comp) - { - using T1 = typename std::iterator_traits::value_type; - - auto n1 = std::distance(first1, last1); - auto n2 = std::distance(first2, last2); - auto n = n1 + n2; - Sequence expect(n); - Sequence out(n); - - auto expect_res = std::set_union(first1, last1, first2, last2, expect.begin(), comp); - auto res = std::set_union(exec, first1, last1, first2, last2, out.begin(), comp); - - EXPECT_TRUE(expect_res - expect.begin() == res - out.begin(), "wrong result for set_union"); - EXPECT_EQ_N(expect.begin(), out.begin(), std::distance(out.begin(), res), "wrong set_union effect"); - } - - template - typename std::enable_if::value, void>::type - operator()(Policy&&, InputIterator1, InputIterator1, InputIterator2, InputIterator2, Compare) - { - } -}; - -template -struct test_set_intersection -{ - template - typename std::enable_if::value, void>::type - operator()(Policy&& exec, InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, - Compare comp) - { - using T1 = typename std::iterator_traits::value_type; - - auto n1 = std::distance(first1, last1); - auto n2 = std::distance(first2, last2); - auto n = n1 + n2; - Sequence expect(n); - Sequence out(n); - - auto expect_res = std::set_intersection(first1, last1, first2, last2, expect.begin(), comp); - auto res = std::set_intersection(exec, first1, last1, first2, last2, out.begin(), comp); - - EXPECT_TRUE(expect_res - expect.begin() == res - out.begin(), "wrong result for set_intersection"); - EXPECT_EQ_N(expect.begin(), out.begin(), std::distance(out.begin(), res), "wrong set_intersection effect"); - } - - template - typename std::enable_if::value, void>::type - operator()(Policy&&, InputIterator1, InputIterator1, InputIterator2, InputIterator2, Compare) - { - } -}; - -template -struct test_set_difference -{ - template - typename std::enable_if::value, void>::type - operator()(Policy&& exec, InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, - Compare comp) - { - using T1 = typename std::iterator_traits::value_type; - - auto n1 = std::distance(first1, last1); - auto n2 = std::distance(first2, last2); - auto n = n1 + n2; - Sequence expect(n); - Sequence out(n); - - auto expect_res = std::set_difference(first1, last1, first2, last2, expect.begin(), comp); - auto res = std::set_difference(exec, first1, last1, first2, last2, out.begin(), comp); - - EXPECT_TRUE(expect_res - expect.begin() == res - out.begin(), "wrong result for set_difference"); - EXPECT_EQ_N(expect.begin(), out.begin(), std::distance(out.begin(), res), "wrong set_difference effect"); - } - - template - typename std::enable_if::value, void>::type - operator()(Policy&&, InputIterator1, InputIterator1, InputIterator2, InputIterator2, Compare) - { - } -}; - -template -struct test_set_symmetric_difference -{ - template - typename std::enable_if::value, void>::type - operator()(Policy&& exec, InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, - Compare comp) - { - using T1 = typename std::iterator_traits::value_type; - - auto n1 = std::distance(first1, last1); - auto n2 = std::distance(first2, last2); - auto n = n1 + n2; - Sequence expect(n); - Sequence out(n); - - auto expect_res = std::set_symmetric_difference(first1, last1, first2, last2, expect.begin(), comp); - auto res = std::set_symmetric_difference(exec, first1, last1, first2, last2, out.begin(), comp); - - EXPECT_TRUE(expect_res - expect.begin() == res - out.begin(), "wrong result for set_symmetric_difference"); - EXPECT_EQ_N(expect.begin(), out.begin(), std::distance(out.begin(), res), - "wrong set_symmetric_difference effect"); - } - - template - typename std::enable_if::value, void>::type - operator()(Policy&&, InputIterator1, InputIterator1, InputIterator2, InputIterator2, Compare) - { - } -}; - -template -void -test_set(Compare compare) -{ - - const std::size_t n_max = 100000; - - // The rand()%(2*n+1) encourages generation of some duplicates. - std::srand(4200); - - for (std::size_t n = 0; n < n_max; n = n <= 16 ? n + 1 : size_t(3.1415 * n)) - { - for (std::size_t m = 0; m < n_max; m = m <= 16 ? m + 1 : size_t(2.71828 * m)) - { - //prepare the input ranges - Sequence in1(n, [](std::size_t k) { return rand() % (2 * k + 1); }); - Sequence in2(m, [m](std::size_t k) { return (m % 2) * rand() + rand() % (k + 1); }); - - std::sort(in1.begin(), in1.end(), compare); - std::sort(in2.begin(), in2.end(), compare); - - invoke_on_all_policies(test_set_union(), in1.begin(), in1.end(), in2.cbegin(), in2.cend(), - compare); - - invoke_on_all_policies(test_set_intersection(), in1.begin(), in1.end(), in2.cbegin(), in2.cend(), - compare); - - invoke_on_all_policies(test_set_difference(), in1.begin(), in1.end(), in2.cbegin(), in2.cend(), - compare); - - invoke_on_all_policies(test_set_symmetric_difference(), in1.begin(), in1.end(), in2.cbegin(), - in2.cend(), compare); - } - } -} - -template -struct test_non_const_set_difference -{ - template - void - operator()(Policy&& exec, InputIterator input_iter, OutputInterator out_iter) - { - set_difference(exec, input_iter, input_iter, input_iter, input_iter, out_iter, non_const(std::less())); - } -}; - -template -struct test_non_const_set_intersection -{ - template - void - operator()(Policy&& exec, InputIterator input_iter, OutputInterator out_iter) - { - set_intersection(exec, input_iter, input_iter, input_iter, input_iter, out_iter, non_const(std::less())); - } -}; - -template -struct test_non_const_set_symmetric_difference -{ - template - void - operator()(Policy&& exec, InputIterator input_iter, OutputInterator out_iter) - { - set_symmetric_difference(exec, input_iter, input_iter, input_iter, input_iter, out_iter, - non_const(std::less())); - } -}; - -template -struct test_non_const_set_union -{ - template - void - operator()(Policy&& exec, InputIterator input_iter, OutputInterator out_iter) - { - set_union(exec, input_iter, input_iter, input_iter, input_iter, out_iter, non_const(std::less())); - } -}; - -int -main() -{ - - test_set(std::less<>()); - test_set, Num>([](const Num& x, const Num& y) { return x < y; }); - - test_set([](const MemoryChecker& val1, const MemoryChecker& val2) -> bool { - return val1.value() < val2.value(); - }); - EXPECT_FALSE(MemoryChecker::alive_objects() < 0, "wrong effect from set algorithms: number of ctors calls < num of dtors calls"); - EXPECT_FALSE(MemoryChecker::alive_objects() > 0, "wrong effect from set algorithms: number of ctors calls > num of dtors calls"); - - test_algo_basic_double(run_for_rnd_fw>()); - - test_algo_basic_double(run_for_rnd_fw>()); - - test_algo_basic_double(run_for_rnd_fw>()); - - test_algo_basic_double(run_for_rnd_fw>()); - - std::cout << done() << std::endl; - - return 0; -} diff --git a/libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set_difference.cc b/libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set_difference.cc new file mode 100644 index 00000000000..a05fad8c47e --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set_difference.cc @@ -0,0 +1,93 @@ +// -*- C++ -*- +// { dg-options "-ltbb" } +// { dg-do run { target c++17 } } +// { dg-timeout-factor 3 } +// { dg-require-effective-target tbb_backend } + +//===-- set.pass.cpp ------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// Note: This file was derived from set.pass.cc which is part of the upstream +// source. + +#include "pstl/pstl_test_config.h" + +#ifdef PSTL_STANDALONE_TESTS + +#include +#include + +#include "pstl/execution" +#include "pstl/algorithm" +#else +#include +#include +#endif // PSTL_STANDALONE_TESTS + +#include "pstl/test_utils.h" + +#include "set_util.h" + +using namespace TestUtils; + +template +struct test_set_difference +{ + template + typename std::enable_if::value, void>::type + operator()(Policy&& exec, InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, + Compare comp) + { + using T1 = typename std::iterator_traits::value_type; + + auto n1 = std::distance(first1, last1); + auto n2 = std::distance(first2, last2); + auto n = n1 + n2; + Sequence expect(n); + Sequence out(n); + + auto expect_res = std::set_difference(first1, last1, first2, last2, expect.begin(), comp); + auto res = std::set_difference(exec, first1, last1, first2, last2, out.begin(), comp); + + EXPECT_TRUE(expect_res - expect.begin() == res - out.begin(), "wrong result for set_difference"); + EXPECT_EQ_N(expect.begin(), out.begin(), std::distance(out.begin(), res), "wrong set_difference effect"); + } + + template + typename std::enable_if::value, void>::type + operator()(Policy&&, InputIterator1, InputIterator1, InputIterator2, InputIterator2, Compare) + { + } +}; + +template +struct test_non_const_set_difference +{ + template + void + operator()(Policy&& exec, InputIterator input_iter, OutputInterator out_iter) + { + set_difference(exec, input_iter, input_iter, input_iter, input_iter, out_iter, non_const(std::less())); + } +}; + +int +main() +{ + test_set_op, float64_t, float64_t>(std::less<>()); + test_set_op>, Num, Num>([](const Num& x, const Num& y) { return x < y; }); + test_set_op, MemoryChecker, MemoryChecker>([](const MemoryChecker& val1, const MemoryChecker& val2) -> bool { + return val1.value() < val2.value(); + }); + EXPECT_FALSE(MemoryChecker::alive_objects() < 0, "wrong effect from set algorithms: number of ctors calls < num of dtors calls"); + EXPECT_FALSE(MemoryChecker::alive_objects() > 0, "wrong effect from set algorithms: number of ctors calls > num of dtors calls"); + + test_algo_basic_double(run_for_rnd_fw>()); + + std::cout << done() << std::endl; +} diff --git a/libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set_intersection.cc b/libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set_intersection.cc new file mode 100644 index 00000000000..4d63fa14da6 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set_intersection.cc @@ -0,0 +1,94 @@ +// -*- C++ -*- +// { dg-options "-ltbb" } +// { dg-do run { target c++17 } } +// { dg-timeout-factor 3 } +// { dg-require-effective-target tbb_backend } + +//===-- set.pass.cpp ------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// Note: This file was derived from set.pass.cc which is part of the upstream +// source. + +#include "pstl/pstl_test_config.h" + +#ifdef PSTL_STANDALONE_TESTS + +#include +#include + +#include "pstl/execution" +#include "pstl/algorithm" +#else +#include +#include +#endif // PSTL_STANDALONE_TESTS + +#include "pstl/test_utils.h" + +#include "set_util.h" + +using namespace TestUtils; + +template +struct test_set_intersection +{ + template + typename std::enable_if::value, void>::type + operator()(Policy&& exec, InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, + Compare comp) + { + using T1 = typename std::iterator_traits::value_type; + + auto n1 = std::distance(first1, last1); + auto n2 = std::distance(first2, last2); + auto n = n1 + n2; + Sequence expect(n); + Sequence out(n); + + auto expect_res = std::set_intersection(first1, last1, first2, last2, expect.begin(), comp); + auto res = std::set_intersection(exec, first1, last1, first2, last2, out.begin(), comp); + + EXPECT_TRUE(expect_res - expect.begin() == res - out.begin(), "wrong result for set_intersection"); + EXPECT_EQ_N(expect.begin(), out.begin(), std::distance(out.begin(), res), "wrong set_intersection effect"); + } + + template + typename std::enable_if::value, void>::type + operator()(Policy&&, InputIterator1, InputIterator1, InputIterator2, InputIterator2, Compare) + { + } +}; + +template +struct test_non_const_set_intersection +{ + template + void + operator()(Policy&& exec, InputIterator input_iter, OutputInterator out_iter) + { + set_intersection(exec, input_iter, input_iter, input_iter, input_iter, out_iter, non_const(std::less())); + } +}; + +int +main() +{ + test_set_op, float64_t, float64_t>(std::less<>()); + test_set_op>, Num, Num>([](const Num& x, const Num& y) { return x < y; }); + + test_set_op, MemoryChecker, MemoryChecker>([](const MemoryChecker& val1, const MemoryChecker& val2) -> bool { + return val1.value() < val2.value(); + }); + EXPECT_FALSE(MemoryChecker::alive_objects() < 0, "wrong effect from set algorithms: number of ctors calls < num of dtors calls"); + EXPECT_FALSE(MemoryChecker::alive_objects() > 0, "wrong effect from set algorithms: number of ctors calls > num of dtors calls"); + + std::cout << done() << std::endl; + + test_algo_basic_double(run_for_rnd_fw>()); +} diff --git a/libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set_symmetric_difference.cc b/libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set_symmetric_difference.cc new file mode 100644 index 00000000000..aaa52f8089d --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set_symmetric_difference.cc @@ -0,0 +1,95 @@ +// -*- C++ -*- +// { dg-options "-ltbb" } +// { dg-do run { target c++17 } } +// { dg-timeout-factor 3 } +// { dg-require-effective-target tbb_backend } + +//===-- set.pass.cpp ------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// Note: This file was derived from set.pass.cc which is part of the upstream +// source. + +#include "pstl/pstl_test_config.h" + +#ifdef PSTL_STANDALONE_TESTS + +#include +#include + +#include "pstl/execution" +#include "pstl/algorithm" +#else +#include +#include +#endif // PSTL_STANDALONE_TESTS + +#include "pstl/test_utils.h" + +#include "set_util.h" + +using namespace TestUtils; + +template +struct test_set_symmetric_difference +{ + template + typename std::enable_if::value, void>::type + operator()(Policy&& exec, InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, + Compare comp) + { + using T1 = typename std::iterator_traits::value_type; + + auto n1 = std::distance(first1, last1); + auto n2 = std::distance(first2, last2); + auto n = n1 + n2; + Sequence expect(n); + Sequence out(n); + + auto expect_res = std::set_symmetric_difference(first1, last1, first2, last2, expect.begin(), comp); + auto res = std::set_symmetric_difference(exec, first1, last1, first2, last2, out.begin(), comp); + + EXPECT_TRUE(expect_res - expect.begin() == res - out.begin(), "wrong result for set_symmetric_difference"); + EXPECT_EQ_N(expect.begin(), out.begin(), std::distance(out.begin(), res), + "wrong set_symmetric_difference effect"); + } + + template + typename std::enable_if::value, void>::type + operator()(Policy&&, InputIterator1, InputIterator1, InputIterator2, InputIterator2, Compare) + { + } +}; + +template +struct test_non_const_set_symmetric_difference +{ + template + void + operator()(Policy&& exec, InputIterator input_iter, OutputInterator out_iter) + { + set_symmetric_difference(exec, input_iter, input_iter, input_iter, input_iter, out_iter, + non_const(std::less())); + } +}; + +int +main() +{ + test_set_op, float64_t, float64_t>(std::less<>()); + test_set_op>, Num, Num>([](const Num& x, const Num& y) { return x < y; }); + test_set_op, MemoryChecker, MemoryChecker>([](const MemoryChecker& val1, const MemoryChecker& val2) -> bool { + return val1.value() < val2.value(); + }); + EXPECT_FALSE(MemoryChecker::alive_objects() < 0, "wrong effect from set algorithms: number of ctors calls < num of dtors calls"); + EXPECT_FALSE(MemoryChecker::alive_objects() > 0, "wrong effect from set algorithms: number of ctors calls > num of dtors calls"); + + test_algo_basic_double(run_for_rnd_fw>()); + + std::cout << done() << std::endl; +} diff --git a/libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set_union.cc b/libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set_union.cc new file mode 100644 index 00000000000..85cde6b0b41 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set_union.cc @@ -0,0 +1,93 @@ +// -*- C++ -*- +// { dg-options "-ltbb" } +// { dg-do run { target c++17 } } +// { dg-timeout-factor 3 } +// { dg-require-effective-target tbb_backend } + +//===-- set.pass.cpp ------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// Note: This file was derived from set.pass.cc which is part of the upstream +// source. + +#include "pstl/pstl_test_config.h" + +#ifdef PSTL_STANDALONE_TESTS + +#include +#include + +#include "pstl/execution" +#include "pstl/algorithm" +#else +#include +#include +#endif // PSTL_STANDALONE_TESTS + +#include "pstl/test_utils.h" + +#include "set_util.h" + +using namespace TestUtils; + +template +struct test_set_union +{ + template + typename std::enable_if::value, void>::type + operator()(Policy&& exec, InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, + Compare comp) + { + using T1 = typename std::iterator_traits::value_type; + + auto n1 = std::distance(first1, last1); + auto n2 = std::distance(first2, last2); + auto n = n1 + n2; + Sequence expect(n); + Sequence out(n); + + auto expect_res = std::set_union(first1, last1, first2, last2, expect.begin(), comp); + auto res = std::set_union(exec, first1, last1, first2, last2, out.begin(), comp); + + EXPECT_TRUE(expect_res - expect.begin() == res - out.begin(), "wrong result for set_union"); + EXPECT_EQ_N(expect.begin(), out.begin(), std::distance(out.begin(), res), "wrong set_union effect"); + } + + template + typename std::enable_if::value, void>::type + operator()(Policy&&, InputIterator1, InputIterator1, InputIterator2, InputIterator2, Compare) + { + } +}; + +template +struct test_non_const_set_union +{ + template + void + operator()(Policy&& exec, InputIterator input_iter, OutputInterator out_iter) + { + set_union(exec, input_iter, input_iter, input_iter, input_iter, out_iter, non_const(std::less())); + } +}; + +int +main() +{ + test_set_op, float64_t, float64_t>(std::less<>()); + test_set_op>, Num, Num>([](const Num& x, const Num& y) { return x < y; }); + test_set_op, MemoryChecker, MemoryChecker>([](const MemoryChecker& val1, const MemoryChecker& val2) -> bool { + return val1.value() < val2.value(); + }); + EXPECT_FALSE(MemoryChecker::alive_objects() < 0, "wrong effect from set algorithms: number of ctors calls < num of dtors calls"); + EXPECT_FALSE(MemoryChecker::alive_objects() > 0, "wrong effect from set algorithms: number of ctors calls > num of dtors calls"); + + test_algo_basic_double(run_for_rnd_fw>()); + + std::cout << done() << std::endl; +} diff --git a/libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set_util.h b/libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set_util.h new file mode 100644 index 00000000000..cd54fc7a6a3 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set_util.h @@ -0,0 +1,76 @@ +// -*- C++ -*- + +//===-- set.pass.cpp ------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// Note: This file was derived from set.pass.cc which is part of the upstream +// source. + +#ifndef __PSTL_TEST_SET_UTIL_H +#define __PSTL_TEST_SET_UTIL_H + +namespace TestUtils +{ + template + struct Num + { + T val; + + Num() : val{} {} + Num(const T& v) : val(v) {} + + //for "includes" checks + template + bool + operator<(const Num& v1) const + { + return val < v1.val; + } + + //The types Type1 and Type2 must be such that an object of type InputIt can be dereferenced and then implicitly converted to both of them + template + operator Num() const + { + return Num((T1)val); + } + + friend bool + operator==(const Num& v1, const Num& v2) + { + return v1.val == v2.val; + } + }; + + template + void + test_set_op(Compare compare) + { + const std::size_t n_max = 100000; + + // The rand()%(2*n+1) encourages generation of some duplicates. + std::srand(4200); + + for (std::size_t n = 0; n < n_max; n = n <= 16 ? n + 1 : size_t(3.1415 * n)) + { + for (std::size_t m = 0; m < n_max; m = m <= 16 ? m + 1 : size_t(2.71828 * m)) + { + //prepare the input ranges + Sequence in1(n, [](std::size_t k) { return rand() % (2 * k + 1); }); + Sequence in2(m, [m](std::size_t k) { return (m % 2) * rand() + rand() % (k + 1); }); + + std::sort(in1.begin(), in1.end(), compare); + std::sort(in2.begin(), in2.end(), compare); + + invoke_on_all_policies(Operation(), in1.begin(), in1.end(), in2.cbegin(), in2.cend(), + compare); + } + } + } +} // namespace TestUtils +#endif // __PSTL_TEST_SET_UTIL_H