On this page
std::compare_three_way_result
| Defined in header <compare> | ||
|---|---|---|
|  | (since C++20) | 
Let t and u denote lvalue of const std::remove_reference_t<T> and const std::remove_reference_t<U> respectively, if the expression t <=> u is well-formed, provides the member typedef type equal to decltype(t <=> u), otherwise there is no member type.
The behavior of a program that adds specializations for std::compare_three_way_result is undefined.
Member types
| Name | Definition | 
|---|---|
| type | the result type of operator<=>on const-qualified lvalue ofTandU | 
Helper types
|  | (since C++20) | 
Possible implementation
|  | 
Example
#include <compare>
#include <iostream>
#include <type_traits>
 
template<class Ord>
void print_cmp_type()
{
    if constexpr (std::is_same_v<Ord, std::strong_ordering>)
        std::cout << "strong ordering\n";
    else if constexpr (std::is_same_v<Ord, std::weak_ordering>)
        std::cout << "weak ordering\n";
    else if constexpr (std::is_same_v<Ord, std::partial_ordering>)
        std::cout << "partial ordering\n";
    else
        std::cout << "illegal comparison result type\n";
}
 
int main()
{
    print_cmp_type<std::compare_three_way_result_t<int>>();
    print_cmp_type<std::compare_three_way_result_t<double>>();
}Output:
strong ordering
partial orderingSee also
| (C++20)
        | the result type of 3-way comparison that supports all 6 operators, is not substitutable, and allows incomparable values (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 and is substitutable (class) | 
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
 https://en.cppreference.com/w/cpp/utility/compare/compare_three_way_result