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

80 lines
4.6 KiB
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

[temp.concept]
# 13 Templates [[temp]](./#temp)
## 13.7 Template declarations [[temp.decls]](temp.decls#temp.concept)
### 13.7.9 Concept definitions [temp.concept]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/templates.tex#L4684)
A [*concept*](#def:concept "13.7.9Concept definitions[temp.concept]") is a template
that defines constraints on its template arguments[.](#1.sentence-1)
[concept-definition:](#nt:concept-definition "13.7.9Concept definitions[temp.concept]")
concept [*concept-name*](#nt:concept-name "13.7.9Concept definitions[temp.concept]") [*attribute-specifier-seq*](dcl.attr.grammar#nt:attribute-specifier-seq "9.13.1Attribute syntax and semantics[dcl.attr.grammar]")opt = [*constraint-expression*](temp.constr.decl#nt:constraint-expression "13.5.3Constrained declarations[temp.constr.decl]") ;
[concept-name:](#nt:concept-name "13.7.9Concept definitions[temp.concept]")
[*identifier*](lex.name#nt:identifier "5.11Identifiers[lex.name]")
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/templates.tex#L4698)
A [*concept-definition*](#nt:concept-definition "13.7.9Concept definitions[temp.concept]") declares a concept[.](#2.sentence-1)
Its [*identifier*](lex.name#nt:identifier "5.11Identifiers[lex.name]") becomes a [*concept-name*](#nt:concept-name "13.7.9Concept definitions[temp.concept]") referring to that concept
within its scope[.](#2.sentence-2)
The optional [*attribute-specifier-seq*](dcl.attr.grammar#nt:attribute-specifier-seq "9.13.1Attribute syntax and semantics[dcl.attr.grammar]") appertains to the concept[.](#2.sentence-3)
[*Example [1](#example-1)*: template<typename T>concept C = requires(T x) {{ x == x } -> std::[convertible_to](concept.convertible#concept:convertible_to "18.4.4Concept convertible_­to[concept.convertible]")<bool>;};
template<typename T>requires C<T> // C constrains f1(T) in [*constraint-expression*](temp.constr.decl#nt:constraint-expression "13.5.3Constrained declarations[temp.constr.decl]") T f1(T x) { return x; }template<C T> // C, as a [*type-constraint*](temp.param#nt:type-constraint "13.2Template parameters[temp.param]"), constrains f2(T) T f2(T x) { return x; } — *end example*]
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/templates.tex#L4721)
A [*concept-definition*](#nt:concept-definition "13.7.9Concept definitions[temp.concept]") shall inhabit a namespace scope ([[basic.scope.namespace]](basic.scope.namespace "6.4.6Namespace scope"))[.](#3.sentence-1)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/templates.tex#L4725)
A concept shall not have [associated constraints](temp.constr.decl#def:associated_constraints "13.5.3Constrained declarations[temp.constr.decl]")[.](#4.sentence-1)
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/templates.tex#L4728)
A concept is not instantiated ([[temp.spec]](temp.spec "13.9Template instantiation and specialization"))[.](#5.sentence-1)
[*Note [1](#note-1)*:
A concept-id ([[temp.names]](temp.names "13.3Names of template specializations")) is evaluated as an expression[.](#5.sentence-2)
A concept cannot be
explicitly instantiated ([[temp.explicit]](temp.explicit "13.9.3Explicit instantiation")),
explicitly specialized ([[temp.expl.spec]](temp.expl.spec "13.9.4Explicit specialization")),
or partially specialized ([[temp.spec.partial]](temp.spec.partial "13.7.6Partial specialization"))[.](#5.sentence-3)
— *end note*]
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/templates.tex#L4738)
The [*constraint-expression*](temp.constr.decl#nt:constraint-expression "13.5.3Constrained declarations[temp.constr.decl]") of a [*concept-definition*](#nt:concept-definition "13.7.9Concept definitions[temp.concept]") is an unevaluated operand ([[expr.context]](expr.context "7.2.3Context dependence"))[.](#6.sentence-1)
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/templates.tex#L4742)
The first declared template parameter of a concept definition is its[*prototype parameter*](#def:prototype_parameter,concept "13.7.9Concept definitions[temp.concept]")[.](#7.sentence-1)
A [*type concept*](#def:concept,type "13.7.9Concept definitions[temp.concept]") is a concept whose prototype parameter
is a type template parameter[.](#7.sentence-2)