Debian Codegraph @

libstdc++-v3/testsuite/25_algorithms/pstl/alg_nonmodifying/reverse.cc

raw
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 //===-- reverse.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 #include "pstl/pstl_test_config.h"
16
17 #ifdef PSTL_STANDALONE_TESTS
18 #include <iterator>
19
20 #include "pstl/execution"
21 #include "pstl/algorithm"
22 #else
23 #include <execution>
24 #include <algorithm>
25 #endif // PSTL_STANDALONE_TESTS
26
27 #include "pstl/test_utils.h"
28
29 using namespace TestUtils;
30
31 struct test_one_policy
32 {
33 #if defined(_PSTL_ICC_18_VC141_TEST_SIMD_LAMBDA_RELEASE_BROKEN) || defined(_PSTL_ICC_17_VC141_TEST_SIMD_LAMBDA_DEBUG_32_BROKEN) || \
34 defined(_PSTL_ICC_16_VC14_TEST_SIMD_LAMBDA_DEBUG_32_BROKEN) // dummy specialization by policy type, in case of broken configuration
35 template <typename Iterator1, typename Iterator2>
36 typename std::enable_if<is_same_iterator_category<Iterator1, std::random_access_iterator_tag>::value, void>::type
37 operator()(__pstl::execution::unsequenced_policy, Iterator1 data_b, Iterator1 data_e, Iterator2 actual_b,
38 Iterator2 actual_e)
39 {
40 }
41 template <typename Iterator1, typename Iterator2>
42 typename std::enable_if<is_same_iterator_category<Iterator1, std::random_access_iterator_tag>::value, void>::type
43 operator()(__pstl::execution::parallel_unsequenced_policy, Iterator1 data_b, Iterator1 data_e, Iterator2 actual_b,
44 Iterator2 actual_e)
45 {
46 }
47 #endif
48
49 template <typename ExecutionPolicy, typename Iterator1, typename Iterator2>
50 typename std::enable_if<!is_same_iterator_category<Iterator1, std::forward_iterator_tag>::value>::type
51 operator()(ExecutionPolicy&& exec, Iterator1 data_b, Iterator1 data_e, Iterator2 actual_b, Iterator2 actual_e)
52 {
53 using namespace std;
54
55 copy(data_b, data_e, actual_b);
56
57 reverse(exec, actual_b, actual_e);
58
59 bool check = equal(data_b, data_e, reverse_iterator<Iterator2>(actual_e));
60
61 EXPECT_TRUE(check, "wrong result of reverse");
62 }
63
64 template <typename ExecutionPolicy, typename Iterator1, typename Iterator2>
65 typename std::enable_if<is_same_iterator_category<Iterator1, std::forward_iterator_tag>::value>::type
66 operator()(ExecutionPolicy&&, Iterator1, Iterator1, Iterator2, Iterator2)
67 {
68 }
69 };
70
71 template <typename T>
72 void
73 test()
74 {
75 const std::size_t max_len = 100000;
76
77 Sequence<T> actual(max_len);
78
79 Sequence<T> data(max_len, [](std::size_t i) { return T(i); });
80
81 for (std::size_t len = 0; len < max_len; len = len <= 16 ? len + 1 : std::size_t(3.1415 * len))
82 {
83 invoke_on_all_policies(test_one_policy(), data.begin(), data.begin() + len, actual.begin(),
84 actual.begin() + len);
85 }
86 }
87
88 template <typename T>
89 struct wrapper
90 {
91 T t;
92 wrapper() {}
93 explicit wrapper(T t_) : t(t_) {}
94 bool
95 operator==(const wrapper<T>& a) const
96 {
97 return t == a.t;
98 }
99 };
100
101 int
102 main()
103 {
104 test<int32_t>();
105 test<uint16_t>();
106 test<float64_t>();
107 #if !defined(_PSTL_ICC_17_TEST_MAC_RELEASE_32_BROKEN)
108 test<wrapper<float64_t>>();
109 #endif
110
111 std::cout << done() << std::endl;
112 return 0;
113 }