]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set_symmetric_difference.cc
libstdc++: Split up pstl/set.cc testcase
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 25_algorithms / pstl / alg_sorting / set_symmetric_difference.cc
1 // -*- C++ -*-
2 // { dg-options "-ltbb" }
3 // { dg-do run { target c++17 } }
4 // { dg-timeout-factor 3 }
5 // { dg-require-effective-target tbb_backend }
6
7 //===-- set.pass.cpp ------------------------------------------------------===//
8 //
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
12 //
13 //===----------------------------------------------------------------------===//
14
15 // Note: This file was derived from set.pass.cc which is part of the upstream
16 // source.
17
18 #include "pstl/pstl_test_config.h"
19
20 #ifdef PSTL_STANDALONE_TESTS
21
22 #include <cmath>
23 #include <chrono>
24
25 #include "pstl/execution"
26 #include "pstl/algorithm"
27 #else
28 #include <execution>
29 #include <algorithm>
30 #endif // PSTL_STANDALONE_TESTS
31
32 #include "pstl/test_utils.h"
33
34 #include "set_util.h"
35
36 using namespace TestUtils;
37
38 template <typename Type>
39 struct test_set_symmetric_difference
40 {
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,
44 Compare comp)
45 {
46 using T1 = typename std::iterator_traits<InputIterator1>::value_type;
47
48 auto n1 = std::distance(first1, last1);
49 auto n2 = std::distance(first2, last2);
50 auto n = n1 + n2;
51 Sequence<T1> expect(n);
52 Sequence<T1> out(n);
53
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);
56
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");
60 }
61
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)
65 {
66 }
67 };
68
69 template <typename T>
70 struct test_non_const_set_symmetric_difference
71 {
72 template <typename Policy, typename InputIterator, typename OutputInterator>
73 void
74 operator()(Policy&& exec, InputIterator input_iter, OutputInterator out_iter)
75 {
76 set_symmetric_difference(exec, input_iter, input_iter, input_iter, input_iter, out_iter,
77 non_const(std::less<T>()));
78 }
79 };
80
81 int
82 main()
83 {
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();
88 });
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");
91
92 test_algo_basic_double<int32_t>(run_for_rnd_fw<test_non_const_set_symmetric_difference<int32_t>>());
93
94 std::cout << done() << std::endl;
95 }