Namespaces
Variants
Views
Actions

std::compare_3way

From cppreference.com
< cpp‎ | algorithm
 
 
Algorithm library
Execution policies (C++17)
Non-modifying sequence operations
(C++11)(C++11)(C++11)
(C++17)
Modifying sequence operations
Operations on uninitialized storage
Partitioning operations
Sorting operations
(C++11)
Binary search operations
Set operations (on sorted ranges)
Heap operations
(C++11)
Minimum/maximum operations
(C++11)
(C++17)
compare_3way
(C++20)
Permutations
Numeric operations
C library
 
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:

  • 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,
  • if a == b equals true, returns std::strong_ordering::equal
  • otherwise, if a < b equals true, returns std::strong_ordering::less
  • otherwise, returns std::strong_ordering::greater
  • Otherwise, if the expression a == b is well-formed and convertible to bool (but a < b is not),
  • if a == b equals true, returns std::strong_equality::equal
  • otherwise, returns std::strong_equality::nonequal
  • Otherwise (if neither a <=> b nor a == b are well-formed), the function is defined as deleted.

Contents

[edit] Parameters

a, b - the values to compare

[edit] Return value

As defined above.

[edit] Example

[edit] See also

compares two ranges using three-way comparison
(function template) [edit]
the result type of 3-way comparison that supports only equality/inequality and is substitutable
(class) [edit]
the result type of 3-way comparison that supports only equality/inequality and is not substitutable
(class) [edit]
the result type of 3-way comparison that supports all 6 operators and is substitutable
(class) [edit]
the result type of 3-way comparison that supports all 6 operators and is not substitutable
(class) [edit]
the result type of 3-way comparison that supports all 6 operators, is not substitutable, and allows incomparable values
(class) [edit]