@@ -66,13 +66,24 @@ 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+ struct TriviallyEqualityComparable {
82+ int i_;
83+
84+ TEST_CONSTEXPR_CXX20 TriviallyEqualityComparable (int i) : i_(i) {}
85+
86+ TEST_CONSTEXPR_CXX20 friend bool operator ==(TriviallyEqualityComparable, TriviallyEqualityComparable) = default ;
7687};
7788
7889struct ModTwoComp {
@@ -136,15 +147,27 @@ TEST_CONSTEXPR_CXX20 bool test() {
136147 types::for_each (types::cpp17_input_iterator_list<int *>(), Test ());
137148
138149 { // 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 );
150+ std::array<NonTrivialMod4Comp , 8 > lhs = {1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 };
151+ std::array<NonTrivialMod4Comp , 8 > rhs = {1 , 2 , 3 , 4 , 1 , 6 , 7 , 8 };
152+ check<NonTrivialMod4Comp *>(std::move (lhs), std::move (rhs), 8 );
142153 }
143154
144155 { // 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 );
156+ std::array<NonTrivialMod4Comp, 8 > lhs = {1 , 2 , 3 , 4 , 7 , 6 , 7 , 8 };
157+ std::array<NonTrivialMod4Comp, 8 > rhs = {1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 };
158+ check<NonTrivialMod4Comp*>(std::move (lhs), std::move (rhs), 4 );
159+ }
160+
161+ { // trivially equaltiy comparable class type to test forwarding to the vectorized version - all elements match
162+ std::array<TriviallyEqualityComparable, 8 > lhs = {1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 };
163+ std::array<TriviallyEqualityComparable, 8 > rhs = {1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 };
164+ check<TriviallyEqualityComparable*>(std::move (lhs), std::move (rhs), 8 );
165+ }
166+
167+ { // trivially equaltiy comparable class type to test forwarding to the vectorized version - not all elements match
168+ std::array<TriviallyEqualityComparable, 8 > lhs = {1 , 2 , 3 , 4 , 7 , 6 , 7 , 8 };
169+ std::array<TriviallyEqualityComparable, 8 > rhs = {1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 };
170+ check<TriviallyEqualityComparable*>(std::move (lhs), std::move (rhs), 4 );
148171 }
149172
150173 return true ;
0 commit comments