From Jason Turner

[temp.pre]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpqvco7uv0/{from.md → to.md} +166 -0
tmp/tmpqvco7uv0/{from.md → to.md} RENAMED
@@ -0,0 +1,166 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ## Preamble <a id="temp.pre">[[temp.pre]]</a>
2
+
3
+ A *template* defines a family of classes, functions, or variables, an
4
+ alias for a family of types, or a concept.
5
+
6
+ ``` bnf
7
+ template-declaration:
8
+ template-head declaration
9
+ template-head concept-definition
10
+ ```
11
+
12
+ ``` bnf
13
+ template-head:
14
+ template '<' template-parameter-list '>' requires-clauseₒₚₜ
15
+ ```
16
+
17
+ ``` bnf
18
+ template-parameter-list:
19
+ template-parameter
20
+ template-parameter-list ',' template-parameter
21
+ ```
22
+
23
+ ``` bnf
24
+ requires-clause:
25
+ requires constraint-logical-or-expression
26
+ ```
27
+
28
+ ``` bnf
29
+ constraint-logical-or-expression:
30
+ constraint-logical-and-expression
31
+ constraint-logical-or-expression '||' constraint-logical-and-expression
32
+ ```
33
+
34
+ ``` bnf
35
+ constraint-logical-and-expression:
36
+ primary-expression
37
+ constraint-logical-and-expression '&&' primary-expression
38
+ ```
39
+
40
+ [*Note 1*: The `>` token following the *template-parameter-list* of a
41
+ *template-declaration* may be the product of replacing a `>{>}` token by
42
+ two consecutive `>` tokens [[temp.names]]. — *end note*]
43
+
44
+ The *declaration* in a *template-declaration* (if any) shall
45
+
46
+ - declare or define a function, a class, or a variable, or
47
+ - define a member function, a member class, a member enumeration, or a
48
+ static data member of a class template or of a class nested within a
49
+ class template, or
50
+ - define a member template of a class or class template, or
51
+ - be a *deduction-guide*, or
52
+ - be an *alias-declaration*.
53
+
54
+ A *template-declaration* is a *declaration*. A declaration introduced by
55
+ a template declaration of a variable is a *variable template*. A
56
+ variable template at class scope is a *static data member template*.
57
+
58
+ [*Example 1*:
59
+
60
+ ``` cpp
61
+ template<class T>
62
+ constexpr T pi = T(3.1415926535897932385L);
63
+ template<class T>
64
+ T circular_area(T r) {
65
+ return pi<T> * r * r;
66
+ }
67
+ struct matrix_constants {
68
+ template<class T>
69
+ using pauli = hermitian_matrix<T, 2>;
70
+ template<class T>
71
+ constexpr static pauli<T> sigma1 = { { 0, 1 }, { 1, 0 } };
72
+ template<class T>
73
+ constexpr static pauli<T> sigma2 = { { 0, -1i }, { 1i, 0 } };
74
+ template<class T>
75
+ constexpr static pauli<T> sigma3 = { { 1, 0 }, { 0, -1 } };
76
+ };
77
+ ```
78
+
79
+ — *end example*]
80
+
81
+ A *template-declaration* can appear only as a namespace scope or class
82
+ scope declaration. Its *declaration* shall not be an
83
+ *export-declaration*. In a function template declaration, the last
84
+ component of the *declarator-id* shall not be a *template-id*.
85
+
86
+ [*Note 2*: That last component may be an *identifier*, an
87
+ *operator-function-id*, a *conversion-function-id*, or a
88
+ *literal-operator-id*. In a class template declaration, if the class
89
+ name is a *simple-template-id*, the declaration declares a class
90
+ template partial specialization [[temp.class.spec]]. — *end note*]
91
+
92
+ In a *template-declaration*, explicit specialization, or explicit
93
+ instantiation the *init-declarator-list* in the declaration shall
94
+ contain at most one declarator. When such a declaration is used to
95
+ declare a class template, no declarator is permitted.
96
+
97
+ A template name has linkage [[basic.link]]. Specializations (explicit or
98
+ implicit) of a template that has internal linkage are distinct from all
99
+ specializations in other translation units. A template, a template
100
+ explicit specialization [[temp.expl.spec]], and a class template partial
101
+ specialization shall not have C linkage. Use of a linkage specification
102
+ other than `"C"` or `"C++"` with any of these constructs is
103
+ conditionally-supported, with *implementation-defined* semantics.
104
+ Template definitions shall obey the one-definition rule
105
+ [[basic.def.odr]].
106
+
107
+ [*Note 3*: Default arguments for function templates and for member
108
+ functions of class templates are considered definitions for the purpose
109
+ of template instantiation [[temp.decls]] and must also obey the
110
+ one-definition rule. — *end note*]
111
+
112
+ A class template shall not have the same name as any other template,
113
+ class, function, variable, enumeration, enumerator, namespace, or type
114
+ in the same scope [[basic.scope]], except as specified in 
115
+ [[temp.class.spec]]. Except that a function template can be overloaded
116
+ either by non-template functions [[dcl.fct]] with the same name or by
117
+ other function templates with the same name [[temp.over]], a template
118
+ name declared in namespace scope or in class scope shall be unique in
119
+ that scope.
120
+
121
+ An entity is *templated* if it is
122
+
123
+ - a template,
124
+ - an entity defined [[basic.def]] or created [[class.temporary]] in a
125
+ templated entity,
126
+ - a member of a templated entity,
127
+ - an enumerator for an enumeration that is a templated entity, or
128
+ - the closure type of a *lambda-expression* [[expr.prim.lambda.closure]]
129
+ appearing in the declaration of a templated entity.
130
+
131
+ [*Note 4*: A local class, a local variable, or a friend function
132
+ defined in a templated entity is a templated entity. — *end note*]
133
+
134
+ A *template-declaration* is written in terms of its template parameters.
135
+ The optional *requires-clause* following a *template-parameter-list*
136
+ allows the specification of constraints [[temp.constr.decl]] on template
137
+ arguments [[temp.arg]]. The *requires-clause* introduces the
138
+ *constraint-expression* that results from interpreting the
139
+ *constraint-logical-or-expression* as a *constraint-expression*. The
140
+ *constraint-logical-or-expression* of a *requires-clause* is an
141
+ unevaluated operand [[expr.context]].
142
+
143
+ [*Note 5*:
144
+
145
+ The expression in a *requires-clause* uses a restricted grammar to avoid
146
+ ambiguities. Parentheses can be used to specify arbitrary expressions in
147
+ a *requires-clause*.
148
+
149
+ [*Example 2*:
150
+
151
+ ``` cpp
152
+ template<int N> requires N == sizeof new unsigned short
153
+ int f(); // error: parentheses required around == expression
154
+ ```
155
+
156
+ — *end example*]
157
+
158
+ — *end note*]
159
+
160
+ A definition of a function template, member function of a class
161
+ template, variable template, or static data member of a class template
162
+ shall be reachable from the end of every definition domain
163
+ [[basic.def.odr]] in which it is implicitly instantiated [[temp.inst]]
164
+ unless the corresponding specialization is explicitly instantiated
165
+ [[temp.explicit]] in some translation unit; no diagnostic is required.
166
+