std::compare_three_way_result

Header: <compare>

Let t and u denote lvalue of const std::remove_reference_t and const std::remove_reference_t 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.

# Declarations

template< class T, class U = T >
struct compare_three_way_result;

(since C++20)

# 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>>();
}

# See also