8 General utilities library [utilities]

8.3 Function objects [function.objects]

Header <experimental/ranges/functional> synopsis

namespace std { namespace experimental { namespace ranges { inline namespace v1 {
  // [func.invoke], invoke:
  template <class F, class... Args>
  result_of_t<F&&(Args&&...)> invoke(F&& f, Args&&... args);

  // [comparisons], comparisons:
  template <class T = void>
    requires see below
  struct equal_to;

  template <class T = void>
    requires see below
  struct not_equal_to;

  template <class T = void>
    requires see below
  struct greater;

  template <class T = void>
    requires see below
  struct less;

  template <class T = void>
    requires see below
  struct greater_equal;

  template <class T = void>
    requires see below
  struct less_equal;

  template <> struct equal_to<void>;
  template <> struct not_equal_to<void>;
  template <> struct greater<void>;
  template <> struct less<void>;
  template <> struct greater_equal<void>;
  template <> struct less_equal<void>;

  // [func.identity], identity:
  struct identity;
}}}}

8.3.1 Function template invoke [func.invoke]

template <class F, class... Args> result_of_t<F&&(Args&&...)> invoke(F&& f, Args&&... args);

Effects: Equivalent to:
return INVOKE(std::forward<F>(f), std::forward<Args>(args)...); ( ISO/IEC 14882:2014 §[func.require]).

8.3.2 Comparisons [comparisons]

The library provides basic function object classes for all of the comparison operators in the language ( ISO/IEC 14882:2014 §[expr.rel], ISO/IEC 14882:2014 §[expr.eq]).

In this section, BUILTIN_PTR_CMP(T, op, U) for types T and U and where op is an equality ( ISO/IEC 14882:2014 §[expr.eq]) or relational operator ( ISO/IEC 14882:2014 §[expr.rel]) is a boolean constant expression. BUILTIN_PTR_CMP(T, op, U) is true if and only if op in the expression declval<T>() op declval<U>() resolves to a built-in operator comparing pointers.

There is an implementation-defined strict total ordering over all pointer values of a given type. This total ordering is consistent with the partial order imposed by the builtin operators <, >, <=, and >=.

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

operator() has effects equivalent to: return equal_to<>{}(x, y);

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

operator() has effects equivalent to: return !equal_to<>{}(x, y);

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

operator() has effects equivalent to: return less<>{}(y, x);

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

operator() has effects equivalent to: return less<>{}(x, y);

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

operator() has effects equivalent to: return !less<>{}(x, y);

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

operator() has effects equivalent to: return !less<>{}(y, x);

template <> struct equal_to<void> { template <class T, class U> requires EqualityComparableWith<T, U> || BUILTIN_PTR_CMP(T, ==, U) constexpr bool operator()(T&& t, U&& u) const; typedef unspecified is_transparent; };

Requires: 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 P shall be equality-preserving ([concepts.lib.general.equality]).

Effects:

  • 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: returns false if either (the converted value of) t precedes u or u precedes t in the implementation-defined strict total order over pointers of type P and otherwise true.

  • Otherwise, equivalent to: return std::forward<T>(t) == std::forward<U>(u);

template <> struct not_equal_to<void> { template <class T, class U> requires EqualityComparableWith<T, U> || BUILTIN_PTR_CMP(T, ==, U) constexpr bool operator()(T&& t, U&& u) const; typedef unspecified is_transparent; };

operator() has effects equivalent to:

return !equal_to<>{}(std::forward<T>(t), std::forward<U>(u));

template <> struct greater<void> { template <class T, class U> requires StrictTotallyOrderedWith<T, U> || BUILTIN_PTR_CMP(U, <, T) constexpr bool operator()(T&& t, U&& u) const; typedef unspecified is_transparent; };

operator() has effects equivalent to:

return less<>{}(std::forward<U>(u), std::forward<T>(t));

template <> struct less<void> { template <class T, class U> requires StrictTotallyOrderedWith<T, U> || BUILTIN_PTR_CMP(T, <, U) constexpr bool operator()(T&& t, U&& u) const; typedef unspecified is_transparent; };

Requires: 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 P shall be equality-preserving ([concepts.lib.general.equality]). For any expressions ET and EU such that decltype((ET)) is T and decltype((EU)) is U, exactly one of less<>{}(ET, EU), less<>{}(EU, ET) or equal_to<>{}(ET, EU) shall be true.

Effects:

  • 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: returns true if (the converted value of) t precedes u in the implementation-defined strict total order over pointers of type P and otherwise false.

  • Otherwise, equivalent to: return std::forward<T>(t) < std::forward<U>(u);

template <> struct greater_equal<void> { template <class T, class U> requires StrictTotallyOrderedWith<T, U> || BUILTIN_PTR_CMP(T, <, U) constexpr bool operator()(T&& t, U&& u) const; typedef unspecified is_transparent; };

operator() has effects equivalent to:

return !less<>{}(std::forward<T>(t), std::forward<U>(u));

template <> struct less_equal<void> { template <class T, class U> requires StrictTotallyOrderedWith<T, U> || BUILTIN_PTR_CMP(U, <, T) constexpr bool operator()(T&& t, U&& u) const; typedef unspecified is_transparent; };

operator() has effects equivalent to:

return !less<>{}(std::forward<U>(u), std::forward<T>(t));

8.3.3 Class identity [func.identity]

struct identity { template <class T> constexpr T&& operator()(T&& t) const noexcept; typedef unspecified is_transparent; };

operator() returns std::forward<T>(t).