17 Concepts library [concepts]

17.7 Callable concepts [concepts.callable]

17.7.1 General [concepts.callable.general]

The concepts in this subclause describe the requirements on function objects ([function.objects]) and their arguments.

17.7.2 Concept Invocable [concept.invocable]

The Invocable concept specifies a relationship between a callable type ([func.def]) F and a set of argument types Args... which can be evaluated by the library function invoke ([func.invoke]).
template<class F, class... Args> concept Invocable = requires(F&& f, Args&&... args) { invoke(std::forward<F>(f), std::forward<Args>(args)...); // not required to be equality-preserving };
[Example
:
A function that generates random numbers can satisfy Invocable, since the invoke function call expression is not required to be equality-preserving ([concepts.equality]).
end example
]

17.7.3 Concept RegularInvocable [concept.regularinvocable]

template<class F, class... Args> concept RegularInvocable = Invocable<F, Args...>;
The invoke function call expression shall be equality-preserving and shall not modify the function object or the arguments ([concepts.equality]).
[Note
:
This requirement supersedes the annotation in the definition of Invocable.
end note
]
[Example
:
A random number generator does not satisfy RegularInvocable.
end example
]
[Note
:
The distinction between Invocable and RegularInvocable is purely semantic.
end note
]

17.7.4 Concept Predicate [concept.predicate]

template<class F, class... Args> concept Predicate = RegularInvocable<F, Args...> && Boolean<invoke_result_t<F, Args...>>;

17.7.5 Concept Relation [concept.relation]

template<class R, class T, class U> concept Relation = Predicate<R, T, T> && Predicate<R, U, U> && CommonReference<const remove_reference_t<T>&, const remove_reference_t<U>&> && Predicate<R, common_reference_t<const remove_reference_t<T>&, const remove_reference_t<U>&>, common_reference_t<const remove_reference_t<T>&, const remove_reference_t<U>&>> && Predicate<R, T, U> && Predicate<R, U, T>;
Let
  • r be an expression such that decltype((r)) is R,
  • t be an expression such that decltype((t)) is T,
  • u be an expression such that decltype((u)) is U, and
  • C be
      common_reference_t<const remove_reference_t<T>&,
                         const remove_reference_t<U>&>
      
Relation<R, T, U> is satisfied only if
  • bool(r(t, u)) == bool(r(C(t), C(u))).
  • bool(r(u, t)) == bool(r(C(u), C(t))).

17.7.6 Concept StrictWeakOrder [concept.strictweakorder]

template<class R, class T, class U> concept StrictWeakOrder = Relation<R, T, U>;
A Relation satisfies StrictWeakOrder only if it imposes a strict weak ordering on its arguments.
The term strict refers to the requirement of an irreflexive relation (!comp(x, x) for all x), and the term weak to requirements that are not as strong as those for a total ordering, but stronger than those for a partial ordering.
If we define equiv(a, b) as !comp(a, b) && !comp(b, a), then the requirements are that comp and equiv both be transitive relations:
  • comp(a, b) && comp(b, c) implies comp(a, c)
  • equiv(a, b) && equiv(b, c) implies equiv(a, c)
[Note
:
Under these conditions, it can be shown that
  • equiv is an equivalence relation,
  • comp induces a well-defined relation on the equivalence classes determined by equiv, and
  • the induced relation is a strict total ordering.
end note
]