11
11
#include < type_traits>
12
12
#include < string_view>
13
13
#include < sstream>
14
+ #include < utility>
14
15
15
16
#if defined(__has_include) && __has_include(<fmt/format.h>)
16
17
#include < fmt/format.h>
@@ -112,6 +113,10 @@ namespace test_suite::detail
112
113
{
113
114
T lhs_;
114
115
116
+ template <class U >
117
+ static constexpr bool integral_comparison =
118
+ std::integral<std::decay_t <T>> && std::integral<std::decay_t <U>>;
119
+
115
120
public:
116
121
explicit first_operand (T lhs) : lhs_(lhs) {}
117
122
@@ -120,47 +125,89 @@ namespace test_suite::detail
120
125
binary_operands<T, U const &>
121
126
operator ==(first_operand &&lhs, U &&rhs)
122
127
{
123
- return {static_cast <bool >( lhs.lhs_ == rhs ), lhs.lhs_ , " ==" , rhs};
128
+ if constexpr (integral_comparison<U>)
129
+ {
130
+ return {std::cmp_equal ( lhs.lhs_ , rhs ), lhs.lhs_ , " ==" , rhs};
131
+ }
132
+ else
133
+ {
134
+ return {static_cast <bool >( lhs.lhs_ == rhs ), lhs.lhs_ , " ==" , rhs};
135
+ }
124
136
}
125
137
126
138
template <class U >
127
139
friend
128
140
binary_operands<T, U const &>
129
141
operator !=(first_operand &&lhs, U &&rhs)
130
142
{
131
- return {static_cast <bool >( lhs.lhs_ != rhs ), lhs.lhs_ , " !=" , rhs};
143
+ if constexpr (integral_comparison<U>)
144
+ {
145
+ return {std::cmp_not_equal ( lhs.lhs_ , rhs ), lhs.lhs_ , " !=" , rhs};
146
+ }
147
+ else
148
+ {
149
+ return {static_cast <bool >( lhs.lhs_ != rhs ), lhs.lhs_ , " !=" , rhs};
150
+ }
132
151
}
133
152
134
153
template <class U >
135
154
friend
136
155
binary_operands<T, U const &>
137
156
operator <(first_operand &&lhs, U &&rhs)
138
157
{
139
- return {static_cast <bool >( lhs.lhs_ < rhs ), lhs.lhs_ , " <" , rhs};
158
+ if constexpr (integral_comparison<U>)
159
+ {
160
+ return {std::cmp_less ( lhs.lhs_ , rhs ), lhs.lhs_ , " <" , rhs};
161
+ }
162
+ else
163
+ {
164
+ return {static_cast <bool >( lhs.lhs_ < rhs ), lhs.lhs_ , " <" , rhs};
165
+ }
140
166
}
141
167
142
168
template <class U >
143
169
friend
144
170
binary_operands<T, U const &>
145
171
operator <=(first_operand &&lhs, U &&rhs)
146
172
{
147
- return {static_cast <bool >( lhs.lhs_ <= rhs ), lhs.lhs_ , " <=" , rhs};
173
+ if constexpr (integral_comparison<U>)
174
+ {
175
+ return {std::cmp_less_equal ( lhs.lhs_ , rhs ), lhs.lhs_ , " <=" , rhs};
176
+ }
177
+ else
178
+ {
179
+ return {static_cast <bool >( lhs.lhs_ <= rhs ), lhs.lhs_ , " <=" , rhs};
180
+ }
148
181
}
149
182
150
183
template <class U >
151
184
friend
152
185
binary_operands<T, U const &>
153
186
operator >(first_operand &&lhs, U &&rhs)
154
187
{
155
- return {static_cast <bool >( lhs.lhs_ > rhs ), lhs.lhs_ , " >" , rhs};
188
+ if constexpr (integral_comparison<U>)
189
+ {
190
+ return {std::cmp_greater ( lhs.lhs_ , rhs ), lhs.lhs_ , " >" , rhs};
191
+ }
192
+ else
193
+ {
194
+ return {static_cast <bool >( lhs.lhs_ > rhs ), lhs.lhs_ , " >" , rhs};
195
+ }
156
196
}
157
197
158
198
template <class U >
159
199
friend
160
200
binary_operands<T, U const &>
161
201
operator >=(first_operand &&lhs, U &&rhs)
162
202
{
163
- return {static_cast <bool >( lhs.lhs_ >= rhs ), lhs.lhs_ , " >=" , rhs};
203
+ if constexpr (integral_comparison<U>)
204
+ {
205
+ return {std::cmp_greater_equal ( lhs.lhs_ , rhs ), lhs.lhs_ , " >=" , rhs};
206
+ }
207
+ else
208
+ {
209
+ return {static_cast <bool >( lhs.lhs_ >= rhs ), lhs.lhs_ , " >=" , rhs};
210
+ }
164
211
}
165
212
166
213
template <class U >
0 commit comments