1 // -*- C++ -*- 2 //===-- reverse.pass.cpp --------------------------------------------------===// 3 // 4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5 // See https://llvm.org/LICENSE.txt for license information. 6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include "support/pstl_test_config.h" 11 12 #include <iterator> 13 #include <execution> 14 #include <algorithm> 15 16 #include "support/utils.h" 17 18 using namespace TestUtils; 19 20 struct test_one_policy 21 { 22 #if _PSTL_ICC_18_VC141_TEST_SIMD_LAMBDA_RELEASE_BROKEN || _PSTL_ICC_17_VC141_TEST_SIMD_LAMBDA_DEBUG_32_BROKEN || \ 23 _PSTL_ICC_16_VC14_TEST_SIMD_LAMBDA_DEBUG_32_BROKEN // dummy specialization by policy type, in case of broken configuration 24 template <typename Iterator1, typename Iterator2> 25 typename std::enable_if<is_same_iterator_category<Iterator1, std::random_access_iterator_tag>::value, void>::type 26 operator()(pstl::execution::unsequenced_policy, Iterator1 data_b, Iterator1 data_e, Iterator2 actual_b, 27 Iterator2 actual_e) 28 { 29 } 30 template <typename Iterator1, typename Iterator2> 31 typename std::enable_if<is_same_iterator_category<Iterator1, std::random_access_iterator_tag>::value, void>::type 32 operator()(pstl::execution::parallel_unsequenced_policy, Iterator1 data_b, Iterator1 data_e, Iterator2 actual_b, 33 Iterator2 actual_e) 34 { 35 } 36 #endif 37 38 template <typename ExecutionPolicy, typename Iterator1, typename Iterator2> 39 typename std::enable_if<!is_same_iterator_category<Iterator1, std::forward_iterator_tag>::value>::type 40 operator()(ExecutionPolicy&& exec, Iterator1 data_b, Iterator1 data_e, Iterator2 actual_b, Iterator2 actual_e) 41 { 42 using namespace std; 43 44 copy(data_b, data_e, actual_b); 45 46 reverse(exec, actual_b, actual_e); 47 48 bool check = equal(data_b, data_e, reverse_iterator<Iterator2>(actual_e)); 49 50 EXPECT_TRUE(check, "wrong result of reverse"); 51 } 52 53 template <typename ExecutionPolicy, typename Iterator1, typename Iterator2> 54 typename std::enable_if<is_same_iterator_category<Iterator1, std::forward_iterator_tag>::value>::type 55 operator()(ExecutionPolicy&&, Iterator1, Iterator1, Iterator2, Iterator2) 56 { 57 } 58 }; 59 60 template <typename T> 61 void 62 test() 63 { 64 const std::size_t max_len = 100000; 65 66 Sequence<T> actual(max_len); 67 68 Sequence<T> data(max_len, [](std::size_t i) { return T(i); }); 69 70 for (std::size_t len = 0; len < max_len; len = len <= 16 ? len + 1 : std::size_t(3.1415 * len)) 71 { 72 invoke_on_all_policies(test_one_policy(), data.begin(), data.begin() + len, actual.begin(), 73 actual.begin() + len); 74 } 75 } 76 77 template <typename T> 78 struct wrapper 79 { 80 T t; 81 wrapper() {} 82 explicit wrapper(T t_) : t(t_) {} 83 bool 84 operator==(const wrapper<T>& a) const 85 { 86 return t == a.t; 87 } 88 }; 89 90 int32_t 91 main() 92 { 93 test<int32_t>(); 94 test<uint16_t>(); 95 test<float64_t>(); 96 #if !_PSTL_ICC_17_TEST_MAC_RELEASE_32_BROKEN 97 test<wrapper<float64_t>>(); 98 #endif 99 100 std::cout << done() << std::endl; 101 return 0; 102 } 103