[AMDGPU][AsmParser][NFC] Translate parsed MIMG instructions to MCInsts automatically.
[llvm-project.git] / pstl / test / std / algorithms / alg.nonmodifying / equal.pass.cpp
bloba6983eae2ff18d4bfe53e6615a8e8a1b840720b5
1 // -*- C++ -*-
2 //===-- equal.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 //===----------------------------------------------------------------------===//
10 // UNSUPPORTED: c++03, c++11, c++14
12 #include "support/pstl_test_config.h"
14 #include <execution>
15 #include <algorithm>
17 #include "support/utils.h"
19 using namespace TestUtils;
21 #define CPP14_ENABLED 0
23 struct UserType
25 size_t key;
26 float32_t f;
27 float64_t d;
28 int32_t i;
30 bool
31 operator()(UserType a, UserType b)
33 return a.key < b.key;
35 bool
36 operator<(UserType a)
38 return a.key < key;
40 bool
41 operator>=(UserType a)
43 return a.key <= key;
45 bool
46 operator<=(UserType a)
48 return a.key >= key;
50 bool
51 operator==(UserType a)
53 return a.key == key;
55 bool
56 operator==(UserType a) const
58 return a.key == key;
60 bool
61 operator!=(UserType a)
63 return a.key != key;
65 UserType operator!()
67 UserType tmp;
68 tmp.key = !key;
69 return tmp;
71 friend std::ostream&
72 operator<<(std::ostream& stream, const UserType a)
74 stream << a.key;
75 return stream;
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) {}
80 UserType&
81 operator=(const UserType& other)
83 key = other.key;
84 return *this;
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)
89 other.key = -1;
90 other.f = 0.0f;
91 other.d = 0.0;
92 other.i = 0;
96 struct test_one_policy
98 template <typename ExecutionPolicy, typename Iterator1, typename Iterator2>
99 void
100 operator()(ExecutionPolicy&& exec, Iterator1 first1, Iterator1 last1, Iterator2 first2, bool is_true_equal)
102 using namespace std;
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()");
108 // testing bool
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
113 #if CPP14_ENABLED
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");
116 #endif
120 template <typename T>
121 void
122 test(size_t bits)
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>
145 void
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>()));
153 main()
156 test<int32_t>(8 * sizeof(int32_t));
157 test<uint16_t>(8 * sizeof(uint16_t));
158 test<float64_t>(53);
159 #if !defined(_PSTL_ICC_16_17_TEST_REDUCTION_BOOL_TYPE_RELEASE_64_BROKEN)
160 test<bool>(1);
161 #endif
162 test<UserType>(256);
164 test_algo_basic_double<int32_t>(run_for_rnd_fw<test_non_const<int32_t>>());
166 std::cout << done() << std::endl;
167 return 0;