@@ -66,14 +66,27 @@ TEST_CONSTEXPR_CXX20 void check(Container1 lhs, Container2 rhs, size_t offset) {
6666#endif
6767}
6868
69- struct NonTrivial {
69+ // Compares modulo 4 to make sure we only forward to the vectorized version if we are trivially equality comparable
70+ struct NonTrivialMod4Comp {
7071 int i_;
7172
72- TEST_CONSTEXPR_CXX20 NonTrivial (int i) : i_(i) {}
73- TEST_CONSTEXPR_CXX20 NonTrivial (NonTrivial && other) : i_(other.i_) { other.i_ = 0 ; }
73+ TEST_CONSTEXPR_CXX20 NonTrivialMod4Comp (int i) : i_(i) {}
74+ TEST_CONSTEXPR_CXX20 NonTrivialMod4Comp (NonTrivialMod4Comp && other) : i_(other.i_) { other.i_ = 0 ; }
7475
75- TEST_CONSTEXPR_CXX20 friend bool operator ==(const NonTrivial& lhs, const NonTrivial& rhs) { return lhs.i_ == rhs.i_ ; }
76+ TEST_CONSTEXPR_CXX20 friend bool operator ==(const NonTrivialMod4Comp& lhs, const NonTrivialMod4Comp& rhs) {
77+ return lhs.i_ % 4 == rhs.i_ % 4 ;
78+ }
79+ };
80+
81+ #if TEST_STD_VER >= 20
82+ struct TriviallyEqualityComparable {
83+ int i_;
84+
85+ TEST_CONSTEXPR_CXX20 TriviallyEqualityComparable (int i) : i_(i) {}
86+
87+ TEST_CONSTEXPR_CXX20 friend bool operator ==(TriviallyEqualityComparable, TriviallyEqualityComparable) = default ;
7688};
89+ #endif // TEST_STD_VER >= 20
7790
7891struct ModTwoComp {
7992 TEST_CONSTEXPR_CXX20 bool operator ()(int lhs, int rhs) { return lhs % 2 == rhs % 2 ; }
@@ -136,16 +149,30 @@ TEST_CONSTEXPR_CXX20 bool test() {
136149 types::for_each (types::cpp17_input_iterator_list<int *>(), Test ());
137150
138151 { // use a non-integer type to also test the general case - all elements match
139- std::array<NonTrivial , 8 > lhs = {1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 };
140- std::array<NonTrivial , 8 > rhs = {1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 };
141- check<NonTrivial *>(std::move (lhs), std::move (rhs), 8 );
152+ std::array<NonTrivialMod4Comp , 8 > lhs = {1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 };
153+ std::array<NonTrivialMod4Comp , 8 > rhs = {1 , 2 , 3 , 4 , 1 , 6 , 7 , 8 };
154+ check<NonTrivialMod4Comp *>(std::move (lhs), std::move (rhs), 8 );
142155 }
143156
144157 { // use a non-integer type to also test the general case - not all elements match
145- std::array<NonTrivial, 8 > lhs = {1 , 2 , 3 , 4 , 7 , 6 , 7 , 8 };
146- std::array<NonTrivial, 8 > rhs = {1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 };
147- check<NonTrivial*>(std::move (lhs), std::move (rhs), 4 );
158+ std::array<NonTrivialMod4Comp, 8 > lhs = {1 , 2 , 3 , 4 , 7 , 6 , 7 , 8 };
159+ std::array<NonTrivialMod4Comp, 8 > rhs = {1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 };
160+ check<NonTrivialMod4Comp*>(std::move (lhs), std::move (rhs), 4 );
161+ }
162+
163+ #if TEST_STD_VER >= 20
164+ { // trivially equality comparable class type to test forwarding to the vectorized version - all elements match
165+ std::array<TriviallyEqualityComparable, 8 > lhs = {1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 };
166+ std::array<TriviallyEqualityComparable, 8 > rhs = {1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 };
167+ check<TriviallyEqualityComparable*>(std::move (lhs), std::move (rhs), 8 );
168+ }
169+
170+ { // trivially equality comparable class type to test forwarding to the vectorized version - not all elements match
171+ std::array<TriviallyEqualityComparable, 8 > lhs = {1 , 2 , 3 , 4 , 7 , 6 , 7 , 8 };
172+ std::array<TriviallyEqualityComparable, 8 > rhs = {1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 };
173+ check<TriviallyEqualityComparable*>(std::move (lhs), std::move (rhs), 4 );
148174 }
175+ #endif // TEST_STD_VER >= 20
149176
150177 return true ;
151178}
0 commit comments