| | |
inlinenamespace/* unspecified */{
inlineconstexpr/* unspecified */ strong_order=/* unspecified */;
} | | (since C++20) |
Call signature | | |
template<class T,class U>
requires/* see below */
constexprstd::strong_ordering strong_order( T&& t, U&& u)noexcept(/* see below */); | | |
| | |
Compares two values using 3-way comparison and produces a result of typestd::strong_ordering
.
Lett andu be expressions andT
andU
denotedecltype((t)) anddecltype((u)) respectively,std::strong_order(t, u) isexpression-equivalent to:
- Ifstd::is_same_v<std::decay_t<T>,std::decay_t<U>> istrue:
- std::strong_ordering(strong_order(t, u)), if it is a well-formed expression with overload resolution performed in a context that does not include a declaration of
std::strong_order
, - otherwise, if
T
is a floating-point type:- ifstd::numeric_limits<T>::is_iec559 istrue, performs the ISO/IEC/IEEE 60559totalOrder comparison of floating-point values and returns that result as a value of typestd::strong_ordering (note: this comparison can distinguish between the positive and negative zero and between the NaNs with different representations),
- otherwise, yields a value of typestd::strong_ordering that is consistent with the ordering observed by
T
's comparison operators,
- otherwise,std::strong_ordering(std::compare_three_way()(t, u)) if it is well-formed.
- In all other cases, the expression is ill-formed, which can result insubstitution failure when it appears in the immediate context of a template instantiation.
Customization point objects
The namestd::strong_order
denotes acustomization point object, which is a constfunction object of aliteralsemiregular
class type. SeeCustomizationPointObject for details.
[edit]Strict total order of IEEE floating-point types
Letx andy be values of same IEEE floating-point type, andtotal_order_less(x, y) be the boolean result indicating ifx precedesy in the strict total order defined bytotalOrder in ISO/IEC/IEEE 60559.
(total_order_less(x, y)|| total_order_less(y, x))==false if and only ifx andy have the same bit pattern.
- if neitherx nory is NaN:
- ifx< y, thentotal_order_less(x, y)==true;
- ifx> y, thentotal_order_less(x, y)==false;
- ifx== y,
- ifx is negative zero andy is positive zero,total_order_less(x, y)==true,
- ifx is not zero andx's exponent field is less thany's, thentotal_order_less(x, y)==(x>0) (only meaningful for decimal floating-point number);
- if eitherx ory is NaN:
- ifx is negative NaN andy is not negative NaN, thentotal_order_less(x, y)==true,
- ifx is not positive NaN andy is positive NaN, thentotal_order_less(x, y)==true,
- if bothx andy are NaNs with the same sign andx's mantissa field is less thany's, thentotal_order_less(x, y)==!std::signbit(x).
[edit]Example
| This section is incomplete Reason: no example |
[edit]See also
| the result type of 3-way comparison that supports all 6 operators and is substitutable (class)[edit] |
| performs 3-way comparison and produces a result of typestd::weak_ordering (customization point object)[edit] |
| performs 3-way comparison and produces a result of typestd::partial_ordering (customization point object)[edit] |
| performs 3-way comparison and produces a result of typestd::strong_ordering , even ifoperator<=> is unavailable (customization point object)[edit] |