23
23
#include < cassert>
24
24
25
25
#include " test_macros.h"
26
+ #include " test_comparisons.h"
26
27
27
28
// std::array is explicitly allowed to be initialized with A a = { init-list };.
28
29
// Disable the missing braces warning for this reason.
29
30
#include " disable_missing_braces_warning.h"
30
31
31
- template <class Array >
32
- void test_compare (const Array& LHS, const Array& RHS) {
33
- typedef std::vector<typename Array::value_type> Vector;
34
- const Vector LHSV (LHS.begin (), LHS.end ());
35
- const Vector RHSV (RHS.begin (), RHS.end ());
36
- assert ((LHS == RHS) == (LHSV == RHSV));
37
- assert ((LHS != RHS) == (LHSV != RHSV));
38
- assert ((LHS < RHS) == (LHSV < RHSV));
39
- assert ((LHS <= RHS) == (LHSV <= RHSV));
40
- assert ((LHS > RHS) == (LHSV > RHSV));
41
- assert ((LHS >= RHS) == (LHSV >= RHSV));
42
- }
43
-
44
- #if TEST_STD_VER > 17
45
- template <class Array >
46
- constexpr bool constexpr_compare (const Array &lhs, const Array &rhs, bool isEqual, bool isLess)
47
- {
48
- if (isEqual)
49
- {
50
- if (!(lhs == rhs)) return false ;
51
- if ( (lhs != rhs)) return false ;
52
- if ( (lhs < rhs)) return false ;
53
- if (!(lhs <= rhs)) return false ;
54
- if ( (lhs > rhs)) return false ;
55
- if (!(lhs >= rhs)) return false ;
56
- }
57
- else if (isLess)
58
- {
59
- if ( (lhs == rhs)) return false ;
60
- if (!(lhs != rhs)) return false ;
61
- if (!(lhs < rhs)) return false ;
62
- if (!(lhs <= rhs)) return false ;
63
- if ( (lhs > rhs)) return false ;
64
- if ( (lhs >= rhs)) return false ;
65
- }
66
- else // greater
67
- {
68
- if ( (lhs == rhs)) return false ;
69
- if (!(lhs != rhs)) return false ;
70
- if ( (lhs < rhs)) return false ;
71
- if ( (lhs <= rhs)) return false ;
72
- if (!(lhs > rhs)) return false ;
73
- if (!(lhs >= rhs)) return false ;
74
- }
75
- return true ;
76
- }
77
- #endif
78
-
79
32
int main ()
80
33
{
81
34
{
@@ -85,25 +38,25 @@ int main()
85
38
C c2 = {1 , 2 , 3 };
86
39
C c3 = {3 , 2 , 1 };
87
40
C c4 = {1 , 2 , 1 };
88
- test_compare ( c1, c2);
89
- test_compare ( c1, c3);
90
- test_compare ( c1, c4);
41
+ assert ( testComparisons6 ( c1, c2, true , false ) );
42
+ assert ( testComparisons6 ( c1, c3, false , true ) );
43
+ assert ( testComparisons6 ( c1, c4, false , false ) );
91
44
}
92
45
{
93
46
typedef int T;
94
47
typedef std::array<T, 0 > C;
95
48
C c1 = {};
96
49
C c2 = {};
97
- test_compare ( c1, c2);
50
+ assert ( testComparisons6 ( c1, c2, true , false ) );
98
51
}
99
52
100
53
#if TEST_STD_VER > 17
101
54
{
102
55
constexpr std::array<int , 3 > a1 = {1 , 2 , 3 };
103
56
constexpr std::array<int , 3 > a2 = {2 , 3 , 4 };
104
- static_assert (constexpr_compare (a1, a1, true , false ), " " );
105
- static_assert (constexpr_compare (a1, a2, false , true ), " " );
106
- static_assert (constexpr_compare (a2, a1, false , false ), " " );
57
+ static_assert (testComparisons6 (a1, a1, true , false ), " " );
58
+ static_assert (testComparisons6 (a1, a2, false , true ), " " );
59
+ static_assert (testComparisons6 (a2, a1, false , false ), " " );
107
60
}
108
61
#endif
109
62
}
0 commit comments