Defined in header <algorithm> | ||
---|---|---|
template< class T, class U > constexpr auto compare_3way( const T& a, const U& b ); | (since C++20) |
Compares two values using three-way comparison and produces a result of the strongest applicable comparison category type.
In detail:
a <=> b
is well-formed, returns its result a == b
and a < b
are both well-formed and convertible to bool
, a == b
equals true
, returns std::strong_ordering::equal
a < b
equals true
, returns std::strong_ordering::less
std::strong_ordering::greater
a == b
is well-formed and convertible to bool
(but a < b
is not), a == b
equals true
, returns std::strong_equality::equal
std::strong_equality::nonequal
a <=> b
nor a == b
are well-formed), the function is defined as deleted. a, b | - | the values to compare |
As defined above.
This function is useful in generic programming, since it uses <
and ==
as fallbacks when <=>
is not available.
(C++20) | compares two ranges using three-way comparison (function template) |
(C++20) | the result type of 3-way comparison that supports only equality/inequality and is substitutable (class) |
(C++20) | the result type of 3-way comparison that supports only equality/inequality and is not substitutable (class) |
(C++20) | the result type of 3-way comparison that supports all 6 operators and is substitutable (class) |
(C++20) | the result type of 3-way comparison that supports all 6 operators and is not substitutable (class) |
(C++20) | the result type of 3-way comparison that supports all 6 operators, is not substitutable, and allows incomparable values (class) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
http://en.cppreference.com/w/cpp/algorithm/compare_3way