std::compare_three_way_result - cppreference.com

C++ | Compiler support | Freestanding and hosted | Language | Standard library | Standard library headers | Named requirements | Feature test macros | Language support library | Concepts library | Diagnostics library | Memory management library | Metaprogramming library | Containers library | Iterators library | Ranges library | Algorithms library | Strings library | Text processing library | Numerics library | Date and time library | Input/output library | Filesystem library | Concurrency support library | Execution control library | Technical specifications | Symbols index | [edit]

From cppreference.com

template<classT,classU=T>structcompare_three_way_result;(since C++20)Let t and u denote lvalue of conststd::remove_reference_t<T> and conststd::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.

If the program adds specializations for std::compare_three_way_result, the behavior is undefined.

Member types

Name Definition typethe result type of operator<=> on const-qualified lvalue of T and UHelper types

template<classT,classU=T>usingcompare_three_way_result_t=compare_three_way_result<T,U>::type;(since C++20)Possible implementation

// recommended by Casey Carter// see also: https://github.com/microsoft/STL/pull/385#discussion_r357894054template<classT,classU=T>usingcompare_three_way_result_t=decltype(std::declval<conststd::remove_reference_t<T>&>()<=>std::declval<conststd::remove_reference_t<U>&>());template<classT,classU=T>structcompare_three_way_result{};template<classT,classU>requiresrequires{typenamecompare_three_way_result_t<T,U>;}structcompare_three_way_result<T,U>{usingtype=compare_three_way_result_t<T,U>;};Example

Run this code

#include<compare>#include<iostream>#include<type_traits>template<classOrd>voidprint_cmp_type(){ifconstexpr(std::is_same_v<Ord,std::strong_ordering>)std::cout<<"strong ordering\n";elseifconstexpr(std::is_same_v<Ord,std::weak_ordering>)std::cout<<"weak ordering\n";elseifconstexpr(std::is_same_v<Ord,std::partial_ordering>)std::cout<<"partial ordering\n";elsestd::cout<<"illegal comparison result type\n";}intmain(){print_cmp_type<std::compare_three_way_result_t<int>>();print_cmp_type<std::compare_three_way_result_t<double>>();}Output:

strong ordering partial ordering See also

(C++20)

the result type of 3-way comparison that supports all 6 operators, is not substitutable, and allows incomparable values
(class)

[edit]

(C++20)

the result type of 3-way comparison that supports all 6 operators and is not substitutable
(class)

[edit]

(C++20)

the result type of 3-way comparison that supports all 6 operators and is substitutable
(class)

[edit]