2 // { dg-options "-ltbb" }
3 // { dg-do run { target c++17 } }
4 // { dg-timeout-factor 3 }
5 // { dg-require-effective-target tbb_backend }
7 //===-- set.pass.cpp ------------------------------------------------------===//
9 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
10 // See https://llvm.org/LICENSE.txt for license information.
11 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
13 //===----------------------------------------------------------------------===//
15 // Note: This file was derived from set.pass.cc which is part of the upstream
18 #include "pstl/pstl_test_config.h"
20 #ifdef PSTL_STANDALONE_TESTS
25 #include "pstl/execution"
26 #include "pstl/algorithm"
30 #endif // PSTL_STANDALONE_TESTS
32 #include "pstl/test_utils.h"
36 using namespace TestUtils
;
38 template <typename Type
>
39 struct test_set_symmetric_difference
41 template <typename Policy
, typename InputIterator1
, typename InputIterator2
, typename Compare
>
42 typename
std::enable_if
<!TestUtils::isReverse
<InputIterator1
>::value
, void>::type
43 operator()(Policy
&& exec
, InputIterator1 first1
, InputIterator1 last1
, InputIterator2 first2
, InputIterator2 last2
,
46 using T1
= typename
std::iterator_traits
<InputIterator1
>::value_type
;
48 auto n1
= std::distance(first1
, last1
);
49 auto n2
= std::distance(first2
, last2
);
51 Sequence
<T1
> expect(n
);
54 auto expect_res
= std::set_symmetric_difference(first1
, last1
, first2
, last2
, expect
.begin(), comp
);
55 auto res
= std::set_symmetric_difference(exec
, first1
, last1
, first2
, last2
, out
.begin(), comp
);
57 EXPECT_TRUE(expect_res
- expect
.begin() == res
- out
.begin(), "wrong result for set_symmetric_difference");
58 EXPECT_EQ_N(expect
.begin(), out
.begin(), std::distance(out
.begin(), res
),
59 "wrong set_symmetric_difference effect");
62 template <typename Policy
, typename InputIterator1
, typename InputIterator2
, typename Compare
>
63 typename
std::enable_if
<TestUtils::isReverse
<InputIterator1
>::value
, void>::type
64 operator()(Policy
&&, InputIterator1
, InputIterator1
, InputIterator2
, InputIterator2
, Compare
)
70 struct test_non_const_set_symmetric_difference
72 template <typename Policy
, typename InputIterator
, typename OutputInterator
>
74 operator()(Policy
&& exec
, InputIterator input_iter
, OutputInterator out_iter
)
76 set_symmetric_difference(exec
, input_iter
, input_iter
, input_iter
, input_iter
, out_iter
,
77 non_const(std::less
<T
>()));
84 test_set_op
<test_set_symmetric_difference
<float64_t
>, float64_t
, float64_t
>(std::less
<>());
85 test_set_op
<test_set_symmetric_difference
<Num
<int64_t>>, Num
<int64_t>, Num
<int32_t>>([](const Num
<int64_t>& x
, const Num
<int32_t>& y
) { return x
< y
; });
86 test_set_op
<test_set_symmetric_difference
<MemoryChecker
>, MemoryChecker
, MemoryChecker
>([](const MemoryChecker
& val1
, const MemoryChecker
& val2
) -> bool {
87 return val1
.value() < val2
.value();
89 EXPECT_FALSE(MemoryChecker::alive_objects() < 0, "wrong effect from set algorithms: number of ctors calls < num of dtors calls");
90 EXPECT_FALSE(MemoryChecker::alive_objects() > 0, "wrong effect from set algorithms: number of ctors calls > num of dtors calls");
92 test_algo_basic_double
<int32_t>(run_for_rnd_fw
<test_non_const_set_symmetric_difference
<int32_t>>());
94 std::cout
<< done() << std::endl
;