std::compare_3way (3) - Linux Manuals
std::compare_3way: std::compare_3way
NAME
std::compare_3way - std::compare_3way
Synopsis
Defined in header <algorithm>
template< class T, class U > (since C++20)
constexpr auto compare_3way( const T& a, const U& b );
Compares two values using three-way comparison and produces a result of the strongest applicable comparison category type.
In detail:
* If the expression a <=> b is well-formed, returns its result
* Otherwise, if the expressions a == b and a < b are both well-formed and convertible to bool,
* Otherwise, if the expression a == b is well-formed and convertible to bool (but a < b is not),
* Otherwise (if neither a <=> b nor a == b are well-formed), the function is defined as deleted.
Parameters
a, b - the values to compare
Return value
As defined above.
Notes
This function is useful in generic programming, since it uses < and == as fallbacks when <=> is not available.
Example
// Run this code
Output:
See also
lexicographical_compare_3way compares two ranges using three-way comparison
(C++20)
strong_equality the result type of 3-way comparison that supports only equality/inequality and is substitutable
(C++20)
weak_equality the result type of 3-way comparison that supports only equality/inequality and is not substitutable