[gram.temp]

# Annex A (informative) Grammar summary [[gram]](./#gram)

## A.11 Templates [gram.temp]

[template-declaration:](temp.pre#nt:template-declaration "13.1 Preamble [temp.pre]")  
[*template-head*](temp.pre#nt:template-head "13.1 Preamble [temp.pre]") [*declaration*](dcl.pre#nt:declaration "9.1 Preamble [dcl.pre]")  
[*template-head*](temp.pre#nt:template-head "13.1 Preamble [temp.pre]") [*concept-definition*](temp.concept#nt:concept-definition "13.7.9 Concept definitions [temp.concept]")

[template-head:](temp.pre#nt:template-head "13.1 Preamble [temp.pre]")  
template < [*template-parameter-list*](temp.pre#nt:template-parameter-list "13.1 Preamble [temp.pre]") > [*requires-clause*](temp.pre#nt:requires-clause "13.1 Preamble [temp.pre]")opt

[template-parameter-list:](temp.pre#nt:template-parameter-list "13.1 Preamble [temp.pre]")  
[*template-parameter*](temp.param#nt:template-parameter "13.2 Template parameters [temp.param]")  
[*template-parameter-list*](temp.pre#nt:template-parameter-list "13.1 Preamble [temp.pre]") , [*template-parameter*](temp.param#nt:template-parameter "13.2 Template parameters [temp.param]")

[requires-clause:](temp.pre#nt:requires-clause "13.1 Preamble [temp.pre]")  
requires [*constraint-logical-or-expression*](temp.pre#nt:constraint-logical-or-expression "13.1 Preamble [temp.pre]")

[constraint-logical-or-expression:](temp.pre#nt:constraint-logical-or-expression "13.1 Preamble [temp.pre]")  
[*constraint-logical-and-expression*](temp.pre#nt:constraint-logical-and-expression "13.1 Preamble [temp.pre]")  
[*constraint-logical-or-expression*](temp.pre#nt:constraint-logical-or-expression "13.1 Preamble [temp.pre]") || [*constraint-logical-and-expression*](temp.pre#nt:constraint-logical-and-expression "13.1 Preamble [temp.pre]")

[constraint-logical-and-expression:](temp.pre#nt:constraint-logical-and-expression "13.1 Preamble [temp.pre]")  
[*primary-expression*](expr.prim.grammar#nt:primary-expression "7.5.1 Grammar [expr.prim.grammar]")  
[*constraint-logical-and-expression*](temp.pre#nt:constraint-logical-and-expression "13.1 Preamble [temp.pre]") && [*primary-expression*](expr.prim.grammar#nt:primary-expression "7.5.1 Grammar [expr.prim.grammar]")

[template-parameter:](temp.param#nt:template-parameter "13.2 Template parameters [temp.param]")  
[*type-parameter*](temp.param#nt:type-parameter "13.2 Template parameters [temp.param]")  
[*parameter-declaration*](dcl.fct#nt:parameter-declaration "9.3.4.6 Functions [dcl.fct]")  
[*type-tt-parameter*](temp.param#nt:type-tt-parameter "13.2 Template parameters [temp.param]")  
[*variable-tt-parameter*](temp.param#nt:variable-tt-parameter "13.2 Template parameters [temp.param]")  
[*concept-tt-parameter*](temp.param#nt:concept-tt-parameter "13.2 Template parameters [temp.param]")

[type-parameter:](temp.param#nt:type-parameter "13.2 Template parameters [temp.param]")  
[*type-parameter-key*](temp.param#nt:type-parameter-key "13.2 Template parameters [temp.param]") ...opt [*identifier*](lex.name#nt:identifier "5.11 Identifiers [lex.name]")opt  
[*type-parameter-key*](temp.param#nt:type-parameter-key "13.2 Template parameters [temp.param]") [*identifier*](lex.name#nt:identifier "5.11 Identifiers [lex.name]")opt = [*type-id*](dcl.name#nt:type-id "9.3.2 Type names [dcl.name]")  
[*type-constraint*](temp.param#nt:type-constraint "13.2 Template parameters [temp.param]") ...opt [*identifier*](lex.name#nt:identifier "5.11 Identifiers [lex.name]")opt  
[*type-constraint*](temp.param#nt:type-constraint "13.2 Template parameters [temp.param]") [*identifier*](lex.name#nt:identifier "5.11 Identifiers [lex.name]")opt = [*type-id*](dcl.name#nt:type-id "9.3.2 Type names [dcl.name]")

[type-parameter-key:](temp.param#nt:type-parameter-key "13.2 Template parameters [temp.param]")  
class  
typename

[type-constraint:](temp.param#nt:type-constraint "13.2 Template parameters [temp.param]")  
[*nested-name-specifier*](expr.prim.id.qual#nt:nested-name-specifier "7.5.5.3 Qualified names [expr.prim.id.qual]")opt [*concept-name*](temp.concept#nt:concept-name "13.7.9 Concept definitions [temp.concept]")  
[*nested-name-specifier*](expr.prim.id.qual#nt:nested-name-specifier "7.5.5.3 Qualified names [expr.prim.id.qual]")opt [*concept-name*](temp.concept#nt:concept-name "13.7.9 Concept definitions [temp.concept]") < [*template-argument-list*](temp.names#nt:template-argument-list "13.3 Names of template specializations [temp.names]")opt >

[type-tt-parameter:](temp.param#nt:type-tt-parameter "13.2 Template parameters [temp.param]")  
[*template-head*](temp.pre#nt:template-head "13.1 Preamble [temp.pre]") [*type-parameter-key*](temp.param#nt:type-parameter-key "13.2 Template parameters [temp.param]") ...opt [*identifier*](lex.name#nt:identifier "5.11 Identifiers [lex.name]")opt  
[*template-head*](temp.pre#nt:template-head "13.1 Preamble [temp.pre]") [*type-parameter-key*](temp.param#nt:type-parameter-key "13.2 Template parameters [temp.param]") [*identifier*](lex.name#nt:identifier "5.11 Identifiers [lex.name]")opt [*type-tt-parameter-default*](temp.param#nt:type-tt-parameter-default "13.2 Template parameters [temp.param]")

[type-tt-parameter-default:](temp.param#nt:type-tt-parameter-default "13.2 Template parameters [temp.param]")  
= [*nested-name-specifier*](expr.prim.id.qual#nt:nested-name-specifier "7.5.5.3 Qualified names [expr.prim.id.qual]")opt [*template-name*](temp.names#nt:template-name "13.3 Names of template specializations [temp.names]")  
= [*nested-name-specifier*](expr.prim.id.qual#nt:nested-name-specifier "7.5.5.3 Qualified names [expr.prim.id.qual]") template [*template-name*](temp.names#nt:template-name "13.3 Names of template specializations [temp.names]")

[variable-tt-parameter:](temp.param#nt:variable-tt-parameter "13.2 Template parameters [temp.param]")  
[*template-head*](temp.pre#nt:template-head "13.1 Preamble [temp.pre]") auto ...opt [*identifier*](lex.name#nt:identifier "5.11 Identifiers [lex.name]")opt  
[*template-head*](temp.pre#nt:template-head "13.1 Preamble [temp.pre]") auto [*identifier*](lex.name#nt:identifier "5.11 Identifiers [lex.name]")opt = [*nested-name-specifier*](expr.prim.id.qual#nt:nested-name-specifier "7.5.5.3 Qualified names [expr.prim.id.qual]")opt [*template-name*](temp.names#nt:template-name "13.3 Names of template specializations [temp.names]")

[concept-tt-parameter:](temp.param#nt:concept-tt-parameter "13.2 Template parameters [temp.param]")  
template < [*template-parameter-list*](temp.pre#nt:template-parameter-list "13.1 Preamble [temp.pre]") > concept ...opt [*identifier*](lex.name#nt:identifier "5.11 Identifiers [lex.name]")opt  
template < [*template-parameter-list*](temp.pre#nt:template-parameter-list "13.1 Preamble [temp.pre]") > concept [*identifier*](lex.name#nt:identifier "5.11 Identifiers [lex.name]")opt = [*nested-name-specifier*](expr.prim.id.qual#nt:nested-name-specifier "7.5.5.3 Qualified names [expr.prim.id.qual]")opt [*template-name*](temp.names#nt:template-name "13.3 Names of template specializations [temp.names]")

[simple-template-id:](temp.names#nt:simple-template-id "13.3 Names of template specializations [temp.names]")  
[*template-name*](temp.names#nt:template-name "13.3 Names of template specializations [temp.names]") < [*template-argument-list*](temp.names#nt:template-argument-list "13.3 Names of template specializations [temp.names]")opt >

[template-id:](temp.names#nt:template-id "13.3 Names of template specializations [temp.names]")  
[*simple-template-id*](temp.names#nt:simple-template-id "13.3 Names of template specializations [temp.names]")  
[*operator-function-id*](over.oper.general#nt:operator-function-id "12.4.1 General [over.oper.general]") < [*template-argument-list*](temp.names#nt:template-argument-list "13.3 Names of template specializations [temp.names]")opt >  
[*literal-operator-id*](over.literal#nt:literal-operator-id "12.6 User-defined literals [over.literal]") < [*template-argument-list*](temp.names#nt:template-argument-list "13.3 Names of template specializations [temp.names]")opt >

[template-name:](temp.names#nt:template-name "13.3 Names of template specializations [temp.names]")  
[*identifier*](lex.name#nt:identifier "5.11 Identifiers [lex.name]")

[template-argument-list:](temp.names#nt:template-argument-list "13.3 Names of template specializations [temp.names]")  
[*template-argument*](temp.names#nt:template-argument "13.3 Names of template specializations [temp.names]") ...opt  
[*template-argument-list*](temp.names#nt:template-argument-list "13.3 Names of template specializations [temp.names]") , [*template-argument*](temp.names#nt:template-argument "13.3 Names of template specializations [temp.names]") ...opt

[template-argument:](temp.names#nt:template-argument "13.3 Names of template specializations [temp.names]")  
[*constant-expression*](expr.const#nt:constant-expression "7.7 Constant expressions [expr.const]")  
[*type-id*](dcl.name#nt:type-id "9.3.2 Type names [dcl.name]")  
[*nested-name-specifier*](expr.prim.id.qual#nt:nested-name-specifier "7.5.5.3 Qualified names [expr.prim.id.qual]")opt [*template-name*](temp.names#nt:template-name "13.3 Names of template specializations [temp.names]")  
[*nested-name-specifier*](expr.prim.id.qual#nt:nested-name-specifier "7.5.5.3 Qualified names [expr.prim.id.qual]") template [*template-name*](temp.names#nt:template-name "13.3 Names of template specializations [temp.names]")

[constraint-expression:](temp.constr.decl#nt:constraint-expression "13.5.3 Constrained declarations [temp.constr.decl]")  
[*logical-or-expression*](expr.log.or#nt:logical-or-expression "7.6.15 Logical OR operator [expr.log.or]")

[deduction-guide:](temp.deduct.guide#nt:deduction-guide "13.7.2.3 Deduction guides [temp.deduct.guide]")  
[*explicit-specifier*](dcl.fct.spec#nt:explicit-specifier "9.2.3 Function specifiers [dcl.fct.spec]")opt [*template-name*](temp.names#nt:template-name "13.3 Names of template specializations [temp.names]") ( [*parameter-declaration-clause*](dcl.fct#nt:parameter-declaration-clause "9.3.4.6 Functions [dcl.fct]") ) -> [*simple-template-id*](temp.names#nt:simple-template-id "13.3 Names of template specializations [temp.names]") [*requires-clause*](temp.pre#nt:requires-clause "13.1 Preamble [temp.pre]")opt ;

[concept-definition:](temp.concept#nt:concept-definition "13.7.9 Concept definitions [temp.concept]")  
concept [*concept-name*](temp.concept#nt:concept-name "13.7.9 Concept definitions [temp.concept]") [*attribute-specifier-seq*](dcl.attr.grammar#nt:attribute-specifier-seq "9.13.1 Attribute syntax and semantics [dcl.attr.grammar]")opt = [*constraint-expression*](temp.constr.decl#nt:constraint-expression "13.5.3 Constrained declarations [temp.constr.decl]") ;

[concept-name:](temp.concept#nt:concept-name "13.7.9 Concept definitions [temp.concept]")  
[*identifier*](lex.name#nt:identifier "5.11 Identifiers [lex.name]")

[typename-specifier:](temp.res.general#nt:typename-specifier "13.8.1 General [temp.res.general]")  
typename [*nested-name-specifier*](expr.prim.id.qual#nt:nested-name-specifier "7.5.5.3 Qualified names [expr.prim.id.qual]") [*identifier*](lex.name#nt:identifier "5.11 Identifiers [lex.name]")  
typename [*nested-name-specifier*](expr.prim.id.qual#nt:nested-name-specifier "7.5.5.3 Qualified names [expr.prim.id.qual]") templateopt [*simple-template-id*](temp.names#nt:simple-template-id "13.3 Names of template specializations [temp.names]")

[explicit-instantiation:](temp.explicit#nt:explicit-instantiation "13.9.3 Explicit instantiation [temp.explicit]")  
externopt template [*declaration*](dcl.pre#nt:declaration "9.1 Preamble [dcl.pre]")

[explicit-specialization:](temp.expl.spec#nt:explicit-specialization "13.9.4 Explicit specialization [temp.expl.spec]")  
template < > [*declaration*](dcl.pre#nt:declaration "9.1 Preamble [dcl.pre]")
