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

4.6 KiB

[temp.concept]

13 Templates [temp]

13.7 Template declarations [temp.decls]

13.7.9 Concept definitions [temp.concept]

1

#

A concept is a template that defines constraints on its template arguments.

concept-definition:
concept concept-name attribute-specifier-seqopt = constraint-expression ;

concept-name:
identifier

2

#

A concept-definition declares a concept.

Its identifier becomes a concept-name referring to that concept within its scope.

The optional attribute-specifier-seq appertains to the concept.

[Example 1: templateconcept C = requires(T x) {{ x == x } -> std::convertible_to;};

templaterequires C // C constrains f1(T) in constraint-expression T f1(T x) { return x; }template // C, as a type-constraint, constrains f2(T) T f2(T x) { return x; } — end example]

3

#

A concept-definition shall inhabit a namespace scope ([basic.scope.namespace]).

4

#

A concept shall not have associated constraints.

5

#

A concept is not instantiated ([temp.spec]).

[Note 1:

A concept-id ([temp.names]) is evaluated as an expression.

A concept cannot be explicitly instantiated ([temp.explicit]), explicitly specialized ([temp.expl.spec]), or partially specialized ([temp.spec.partial]).

— end note]

6

#

The constraint-expression of a concept-definition is an unevaluated operand ([expr.context]).

7

#

The first declared template parameter of a concept definition is itsprototype parameter.

A type concept is a concept whose prototype parameter is a type template parameter.