2 //===-- equal.pass.cpp ----------------------------------------------------===//
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
8 //===----------------------------------------------------------------------===//
10 // UNSUPPORTED: c++03, c++11, c++14
12 #include "support/pstl_test_config.h"
17 #include "support/utils.h"
19 using namespace TestUtils
;
21 #define CPP14_ENABLED 0
31 operator()(UserType a
, UserType b
)
41 operator>=(UserType a
)
46 operator<=(UserType a
)
51 operator==(UserType a
)
56 operator==(UserType a
) const
61 operator!=(UserType a
)
72 operator<<(std::ostream
& stream
, const UserType a
)
78 UserType() : key(-1), f(0.0f
), d(0.0), i(0) {}
79 UserType(size_t Number
) : key(Number
), f(0.0f
), d(0.0), i(0) {}
81 operator=(const UserType
& other
)
86 UserType(const UserType
& other
) : key(other
.key
), f(other
.f
), d(other
.d
), i(other
.i
) {}
87 UserType(UserType
&& other
) : key(other
.key
), f(other
.f
), d(other
.d
), i(other
.i
)
96 struct test_one_policy
98 template <typename ExecutionPolicy
, typename Iterator1
, typename Iterator2
>
100 operator()(ExecutionPolicy
&& exec
, Iterator1 first1
, Iterator1 last1
, Iterator2 first2
, bool is_true_equal
)
104 auto expected
= equal(first1
, last1
, first2
);
105 auto actual
= equal(exec
, first1
, last1
, first2
);
106 EXPECT_EQ(expected
, actual
, "result for equal for random-access iterator, checking against std::equal()");
109 EXPECT_TRUE(is_true_equal
== actual
, "result for equal for random-access iterator, bool");
111 //add C++14 equal symantics tests
112 //add more cases for inCopy size less than in
114 auto actualr14
= std::equal(in
.cbegin(), in
.cend(), inCopy
.cbegin(), inCopy
.cend());
115 EXPECT_EQ(expected
, actualr14
, "result for equal for random-access iterator");
120 template <typename T
>
124 for (size_t n
= 1; n
<= 100000; n
= n
<= 16 ? n
+ 1 : size_t(3.1415 * n
))
127 // Sequence of odd values
128 Sequence
<T
> in(n
, [bits
](size_t k
) { return T(2 * HashBits(k
, bits
- 1) ^ 1); });
129 Sequence
<T
> inCopy(in
);
131 invoke_on_all_policies(test_one_policy(), in
.begin(), in
.end(), inCopy
.begin(), true);
132 invoke_on_all_policies(test_one_policy(), in
.cbegin(), in
.cend(), inCopy
.cbegin(), true);
134 // testing bool !equal()
135 inCopy
[0] = !inCopy
[0];
136 invoke_on_all_policies(test_one_policy(), in
.begin(), in
.end(), inCopy
.begin(), false);
137 invoke_on_all_policies(test_one_policy(), in
.cbegin(), in
.cend(), inCopy
.cbegin(), false);
141 template <typename T
>
142 struct test_non_const
144 template <typename Policy
, typename FirstIterator
, typename SecondInterator
>
146 operator()(Policy
&& exec
, FirstIterator first_iter
, SecondInterator second_iter
)
148 equal(exec
, first_iter
, first_iter
, second_iter
, second_iter
, non_const(std::equal_to
<T
>()));
156 test
<int32_t>(8 * sizeof(int32_t));
157 test
<uint16_t>(8 * sizeof(uint16_t));
159 #if !defined(_PSTL_ICC_16_17_TEST_REDUCTION_BOOL_TYPE_RELEASE_64_BROKEN)
164 test_algo_basic_double
<int32_t>(run_for_rnd_fw
<test_non_const
<int32_t>>());
166 std::cout
<< done() << std::endl
;