Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/standard library/synth-three-way"

From cppreference.com
m (Minor fix.)
m ({{mark expos}}, fmt)
 
Line 2: Line 2:
 
{{cpp/standard library/navbar}}
 
{{cpp/standard library/navbar}}
 
{{dcl begin}}
 
{{dcl begin}}
{{dcl|since=c++20|1=
+
{{dcl|num=1|since=c++20|notes={{mark expos}}|1=
constexpr auto synth-three-way = /* see below */; // exposition only
+
constexpr auto synth-three-way = /* see below */;
 
}}
 
}}
{{dcl|since=c++20|1=
+
{{dcl|num=2|since=c++20|notes={{mark expos}}|1=
 
template< class T, class U = T >
 
template< class T, class U = T >
using synth-three-way-result =                   // exposition only
+
using synth-three-way-result =
 
     decltype(synth-three-way(std::declval<T&>(), std::declval<U&>()));
 
     decltype(synth-three-way(std::declval<T&>(), std::declval<U&>()));
 
}}
 
}}
 
{{dcl end}}
 
{{dcl end}}
  
{{tti|synth-three-way}} is an exposition-only function object whose {{c/core|operator()}} behaves as the synthesized three-way comparison function.
+
@1@ A function object whose {{c/core|operator()}} behaves as the synthesized three-way comparison function. Equivalent to:
 
+
{{tti|synth-three-way-result}} is an exposition-only type, it is the return type of the {{c/core|operator()}} of {{tti|synth-three-way}}.
+
 
+
{{tti|synth-three-way}} is defined as follows:
+
 
{{source|1=
 
{{source|1=
 
constexpr auto synth-three-way =
 
constexpr auto synth-three-way =
Line 38: Line 34:
 
     };
 
     };
 
}}
 
}}
 +
 +
@2@ The return type of the {{c/core|operator()}} of {{v|1}} ({{tti|synth-three-way}}).
  
 
===Parameters===
 
===Parameters===

Latest revision as of 23:44, 16 August 2023

constexpr auto synth-three-way = /* see below */;
(1) (since C++20)
(exposition only*)
template< class T, class U = T >

using synth-three-way-result =

    decltype(synth-three-way(std::declval<T&>(), std::declval<U&>()));
(2) (since C++20)
(exposition only*)
1) A function object whose operator() behaves as the synthesized three-way comparison function. Equivalent to:
constexpr auto synth-three-way =
    []<class T, class U>(const T& t, const U& u)
        requires requires
        {
            { t < u } -> boolean-testable;
            { u < t } -> boolean-testable;
        }
    {
        if constexpr (std::three_way_comparable_with<T, U>)
            return t <=> u;
        else
        {
            if (t < u)
                return std::weak_ordering::less;
            if (u < t)
                return std::weak_ordering::greater;
            return std::weak_ordering::equivalent;
        }
    };
2) The return type of the operator() of (1) (synth-three-way).

[edit] Parameters

t, u - the values to be compared

[edit] Return value

The compare result.

[edit] See also

(removed in C++20)(removed in C++20)(removed in C++20)(removed in C++20)(removed in C++20)(C++20)
lexicographically compares the values in the pair
(function template) [edit]
(removed in C++20)(removed in C++20)(removed in C++20)(removed in C++20)(removed in C++20)(C++20)
lexicographically compares the values in the tuple
(function template) [edit]
(C++11)(C++11)(removed in C++20)(C++11)(removed in C++20)(C++11)(removed in C++20)(C++11)(removed in C++20)(C++11)(removed in C++20)(C++20)
lexicographically compares the values of two arrays
(function template) [edit]
(removed in C++20)(removed in C++20)(removed in C++20)(removed in C++20)(removed in C++20)(C++20)
lexicographically compares the values of two deques
(function template) [edit]
(C++11)(C++11)(removed in C++20)(C++11)(removed in C++20)(C++11)(removed in C++20)(C++11)(removed in C++20)(C++11)(removed in C++20)(C++20)
lexicographically compares the values of two forward_lists
(function template) [edit]
(removed in C++20)(removed in C++20)(removed in C++20)(removed in C++20)(removed in C++20)(C++20)
lexicographically compares the values of two lists
(function template) [edit]
(removed in C++20)(removed in C++20)(removed in C++20)(removed in C++20)(removed in C++20)(C++20)
lexicographically compares the values of two vectors
(function template) [edit]
(removed in C++20)(removed in C++20)(removed in C++20)(removed in C++20)(removed in C++20)(C++20)
lexicographically compares the values of two maps
(function template) [edit]
(removed in C++20)(removed in C++20)(removed in C++20)(removed in C++20)(removed in C++20)(C++20)
lexicographically compares the values of two multimaps
(function template) [edit]
(removed in C++20)(removed in C++20)(removed in C++20)(removed in C++20)(removed in C++20)(C++20)
lexicographically compares the values of two sets
(function template) [edit]
(removed in C++20)(removed in C++20)(removed in C++20)(removed in C++20)(removed in C++20)(C++20)
lexicographically compares the values of two multisets
(function template) [edit]