# synth-three-way, synth-three-way-result

From cppreference.com
< cpp‎ | standard library

constexpr auto synth-three-way = /* see below */; // exposition only |  | (since C++20)
template< class T, class U = T > using synth-three-way-result = // exposition only decltype(synth-three-way(std::declval<T&>(), std::declval<U&>())); |  | (since C++20)

`synth-three-way` is an exposition-only function object whose operator() behaves as the synthesized three-way comparison function.

`synth-three-way-result` is an exposition-only type, it is the return type of the operator() of `synth-three-way`.

`synth-three-way` is defined as follows:

    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;
            }
        };

### Parameters

t, u | - | the values to be compared

### Return value

The compare result.

### See also

operator==operator!=operator<operator<=operator>operator>=operator<=> (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)
operator==operator!=operator<operator<=operator>operator>=operator<=> (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)
operator==operator!=operator<operator<=operator>operator>=operator<=> (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 array (function template)
operator==operator!=operator<operator<=operator>operator>=operator<=> (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 deque (function template)
operator==operator!=operator<operator<=operator>operator>=operator<=> (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 forward_list (function template)
operator==operator!=operator<operator<=operator>operator>=operator<=> (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 list (function template)
operator==operator!=operator<operator<=operator>operator>=operator<=> (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 vector (function template)
operator==operator!=operator<operator<=operator>operator>=operator<=> (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 map (function template)
operator==operator!=operator<operator<=operator>operator>=operator<=> (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 multimap (function template)
operator==operator!=operator<operator<=operator>operator>=operator<=> (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 set (function template)
operator==operator!=operator<operator<=operator>operator>=operator<=> (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 multiset (function template)

Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/standard_library/synth-three-way&oldid=151526"