20 General utilities library [utilities] (original) (raw)

20.14 Function objects [function.objects]

20.14.8 Comparisons [comparisons]

20.14.8.1 General [comparisons.general]

The library provides basic function object classes for all of the comparison operators in the language ([expr.rel], [expr.eq]).

For templates less, greater, less_­equal, andgreater_­equal, the specializations for any pointer type yield a result consistent with the implementation-defined strict total order over pointers ([defns.order.ptr]).

[Note 1:

If a < b is well-defined for pointers a and b of type P, then (a < b) == less<P>()(a, b),(a > b) == greater<P>()(a, b), and so forth.

— _end note_]

For template specializations less<void>, greater<void>,less_­equal<void>, and greater_­equal<void>, if the call operator calls a built-in operator comparing pointers, the call operator yields a result consistent with the implementation-defined strict total order over pointers.

20.14.8.2 Class template equal_­to [comparisons.equal.to]

template<class T = void> struct equal_to { constexpr bool operator()(const T& x, const T& y) const;};

constexpr bool operator()(const T& x, const T& y) const;

template<> struct equal_to<void> { template<class T, class U> constexpr auto operator()(T&& t, U&& u) const -> decltype(std::forward<T>(t) == std::forward<U>(u));using is_transparent = _unspecified_;};

template<class T, class U> constexpr auto operator()(T&& t, U&& u) const -> decltype(std::forward<T>(t) == std::forward<U>(u));

Returns: std​::​forward<T>(t) == std​::​forward<U>(u).

20.14.8.3 Class template not_­equal_­to [comparisons.not.equal.to]

template<class T = void> struct not_equal_to { constexpr bool operator()(const T& x, const T& y) const;};

constexpr bool operator()(const T& x, const T& y) const;

template<> struct not_equal_to<void> { template<class T, class U> constexpr auto operator()(T&& t, U&& u) const -> decltype(std::forward<T>(t) != std::forward<U>(u));using is_transparent = _unspecified_;};

template<class T, class U> constexpr auto operator()(T&& t, U&& u) const -> decltype(std::forward<T>(t) != std::forward<U>(u));

Returns: std​::​forward<T>(t) != std​::​forward<U>(u).

20.14.8.4 Class template greater [comparisons.greater]

template<class T = void> struct greater { constexpr bool operator()(const T& x, const T& y) const;};

constexpr bool operator()(const T& x, const T& y) const;

template<> struct greater<void> { template<class T, class U> constexpr auto operator()(T&& t, U&& u) const -> decltype(std::forward<T>(t) > std::forward<U>(u));using is_transparent = _unspecified_;};

template<class T, class U> constexpr auto operator()(T&& t, U&& u) const -> decltype(std::forward<T>(t) > std::forward<U>(u));

Returns: std​::​forward<T>(t) > std​::​forward<U>(u).

20.14.8.5 Class template less [comparisons.less]

template<class T = void> struct less { constexpr bool operator()(const T& x, const T& y) const;};

constexpr bool operator()(const T& x, const T& y) const;

template<> struct less<void> { template<class T, class U> constexpr auto operator()(T&& t, U&& u) const -> decltype(std::forward<T>(t) < std::forward<U>(u));using is_transparent = _unspecified_;};

template<class T, class U> constexpr auto operator()(T&& t, U&& u) const -> decltype(std::forward<T>(t) < std::forward<U>(u));

Returns: std​::​forward<T>(t) < std​::​forward<U>(u).

20.14.8.6 Class template greater_­equal [comparisons.greater.equal]

template<class T = void> struct greater_equal { constexpr bool operator()(const T& x, const T& y) const;};

constexpr bool operator()(const T& x, const T& y) const;

template<> struct greater_equal<void> { template<class T, class U> constexpr auto operator()(T&& t, U&& u) const -> decltype(std::forward<T>(t) >= std::forward<U>(u));using is_transparent = _unspecified_;};

template<class T, class U> constexpr auto operator()(T&& t, U&& u) const -> decltype(std::forward<T>(t) >= std::forward<U>(u));

Returns: std​::​forward<T>(t) >= std​::​forward<U>(u).

20.14.8.7 Class template less_­equal [comparisons.less.equal]

template<class T = void> struct less_equal { constexpr bool operator()(const T& x, const T& y) const;};

constexpr bool operator()(const T& x, const T& y) const;

template<> struct less_equal<void> { template<class T, class U> constexpr auto operator()(T&& t, U&& u) const -> decltype(std::forward<T>(t) <= std::forward<U>(u));using is_transparent = _unspecified_;};

template<class T, class U> constexpr auto operator()(T&& t, U&& u) const -> decltype(std::forward<T>(t) <= std::forward<U>(u));

Returns: std​::​forward<T>(t) <= std​::​forward<U>(u).

20.14.8.8 Class compare_­three_­way [comparisons.three.way]

In this subclause, BUILTIN-PTR-THREE-WAY(T, U)for types T and U is a boolean constant expression.

BUILTIN-PTR-THREE-WAY(T, U) is trueif and only if <=> in the expressiondeclval<T>() <=> declval<U>() resolves to a built-in operator comparing pointers.

struct compare_three_way { template<class T, class U> requires three_way_comparable_with<T, U> || BUILTIN-PTR-THREE-WAY(T, U) constexpr auto operator()(T&& t, U&& u) const;using is_transparent = unspecified;};

template<class T, class U> requires three_way_comparable_with<T, U> || _BUILTIN-PTR-THREE-WAY_(T, U) constexpr auto operator()(T&& t, U&& u) const;

Preconditions: If the expression std​::​forward<T>(t) <=> std​::​forward<U>(u) results in a call to a built-in operator <=> comparing pointers of type P, the conversion sequences from both T and U to Pare equality-preserving ([concepts.equality]).

Effects: