Files
2025-10-25 03:02:53 +03:00

8.0 KiB
Raw Permalink Blame History

[concepts.callable]

18 Concepts library [concepts]

18.7 Callable concepts [concepts.callable]

18.7.1 General [concepts.callable.general]

1

#

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

18.7.2 Concept invocable [concept.invocable]

1

#

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](#concept:invocable "18.7.2Concept invocable[concept.invocable]") = requires(F&& f, Args&&... args) { invoke(std::forward<F>(f), std::forward<Args>(args)...); // not required to be equality-preserving };

2

#

[Example 1:

A function that generates random numbers can model invocable, since the invoke function call expression is not required to be equality-preserving ([concepts.equality]).

— end example]

18.7.3 Concept regular_invocable [concept.regularinvocable]

🔗

template<class F, class... Args> concept [regular_invocable](#concept:regular_invocable "18.7.3Concept regular_­invocable[concept.regularinvocable]") = [invocable](#concept:invocable "18.7.2Concept invocable[concept.invocable]")<F, Args...>;

1

#

The invoke function call expression shall be equality-preserving ([concepts.equality]) and shall not modify the function object or the arguments.

[Note 1:

This requirement supersedes the annotation in the definition ofinvocable.

— end note]

2

#

[Example 1:

A random number generator does not model regular_invocable.

— end example]

3

#

[Note 2:

The distinction between invocable and regular_invocable is purely semantic.

— end note]

18.7.4 Concept predicate [concept.predicate]

🔗

template<class F, class... Args> concept [predicate](#concept:predicate "18.7.4Concept predicate[concept.predicate]") = [regular_invocable](#concept:regular_invocable "18.7.3Concept regular_­invocable[concept.regularinvocable]")<F, Args...> && [boolean-testable](concept.booleantestable#concept:boolean-testable "18.5.2Boolean testability[concept.booleantestable]")<invoke_result_t<F, Args...>>;

18.7.5 Concept relation [concept.relation]

🔗

template<class R, class T, class U> concept [relation](#concept:relation "18.7.5Concept relation[concept.relation]") = [predicate](#concept:predicate "18.7.4Concept predicate[concept.predicate]")<R, T, T> && [predicate](#concept:predicate "18.7.4Concept predicate[concept.predicate]")<R, U, U> && [predicate](#concept:predicate "18.7.4Concept predicate[concept.predicate]")<R, T, U> && [predicate](#concept:predicate "18.7.4Concept predicate[concept.predicate]")<R, U, T>;

18.7.6 Concept equivalence_relation [concept.equiv]

🔗

template<class R, class T, class U> concept [equivalence_relation](#concept:equivalence_relation "18.7.6Concept equivalence_­relation[concept.equiv]") = [relation](#concept:relation "18.7.5Concept relation[concept.relation]")<R, T, U>;

1

#

A relation models equivalence_relation only if it imposes an equivalence relation on its arguments.

18.7.7 Concept strict_weak_order [concept.strictweakorder]

🔗

template<class R, class T, class U> concept [strict_weak_order](#concept:strict_weak_order "18.7.7Concept strict_­weak_­order[concept.strictweakorder]") = [relation](#concept:relation "18.7.5Concept relation[concept.relation]")<R, T, U>;

1

#

A relation models strict_weak_order only if it imposes a strict weak ordering on its arguments.

2

#

The termstrict refers to the requirement of an irreflexive relation (!comp(x, x) for all x), and the termweak to requirements that are not as strong as those for a total ordering, but stronger than those for a partial ordering.

If we defineequiv(a, b) as!comp(a, b) && !comp(b, a), then the requirements are thatcomp andequiv both be transitive relations:

comp(a, b) && comp(b, c) impliescomp(a, c)

equiv(a, b) && equiv(b, c) impliesequiv(a, c)

3

#

[Note 1:

Under these conditions, it can be shown that

equiv is an equivalence relation,

comp induces a well-defined relation on the equivalence classes determined byequiv, and

the induced relation is a strict total ordering.

— end note]