- tmp/tmply4x70_c/{from.md → to.md} +166 -118
tmp/tmply4x70_c/{from.md → to.md}
RENAMED
|
@@ -4,20 +4,21 @@ The syntax for *template-parameter*s is:
|
|
| 4 |
|
| 5 |
``` bnf
|
| 6 |
template-parameter:
|
| 7 |
type-parameter
|
| 8 |
parameter-declaration
|
|
|
|
|
|
|
|
|
|
| 9 |
```
|
| 10 |
|
| 11 |
``` bnf
|
| 12 |
type-parameter:
|
| 13 |
type-parameter-key '...'ₒₚₜ identifierₒₚₜ
|
| 14 |
type-parameter-key identifierₒₚₜ '=' type-id
|
| 15 |
type-constraint '...'ₒₚₜ identifierₒₚₜ
|
| 16 |
type-constraint identifierₒₚₜ '=' type-id
|
| 17 |
-
template-head type-parameter-key '...'ₒₚₜ identifierₒₚₜ
|
| 18 |
-
template-head type-parameter-key identifierₒₚₜ '=' id-expression
|
| 19 |
```
|
| 20 |
|
| 21 |
``` bnf
|
| 22 |
type-parameter-key:
|
| 23 |
class
|
|
@@ -28,83 +29,150 @@ type-parameter-key:
|
|
| 28 |
type-constraint:
|
| 29 |
nested-name-specifierₒₚₜ concept-name
|
| 30 |
nested-name-specifierₒₚₜ concept-name '<' template-argument-listₒₚₜ '>'
|
| 31 |
```
|
| 32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
The component names of a *type-constraint* are its *concept-name* and
|
| 34 |
those of its *nested-name-specifier* (if any).
|
| 35 |
|
| 36 |
[*Note 1*: The `>` token following the *template-parameter-list* of a
|
| 37 |
-
*type-parameter*
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
There is no semantic difference between `class` and `typename` in a
|
| 41 |
*type-parameter-key*. `typename` followed by an *unqualified-id* names a
|
| 42 |
template type parameter. `typename` followed by a *qualified-id* denotes
|
| 43 |
-
the type in a
|
|
|
|
| 44 |
|
| 45 |
-
*
|
| 46 |
-
*identifier* is a *type-parameter*.
|
| 47 |
-
|
| 48 |
-
[*Example 1*:
|
| 49 |
|
| 50 |
``` cpp
|
| 51 |
class T { ... };
|
| 52 |
int i;
|
| 53 |
|
| 54 |
template<class T, T i> void f(T t) {
|
| 55 |
-
T t1 = i; // template
|
| 56 |
::T t2 = ::i; // global namespace members T and i
|
| 57 |
}
|
| 58 |
```
|
| 59 |
|
| 60 |
-
Here, the template `f` has a
|
| 61 |
-
unnamed
|
| 62 |
|
| 63 |
— *end example*]
|
| 64 |
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
declaration.
|
| 68 |
|
| 69 |
-
The *identifier* in a *
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
or *template-name* (if declared with `template`) in the scope of the
|
| 73 |
-
template declaration.
|
| 74 |
|
| 75 |
-
|
|
|
|
|
|
|
|
|
|
| 76 |
|
| 77 |
-
|
| 78 |
-
example,
|
| 79 |
-
|
| 80 |
-
``` cpp
|
| 81 |
-
template<class T> class myarray { ... };
|
| 82 |
-
|
| 83 |
-
template<class K, class V, template<class T> class C = myarray>
|
| 84 |
-
class Map {
|
| 85 |
-
C<K> key;
|
| 86 |
-
C<V> value;
|
| 87 |
-
};
|
| 88 |
-
```
|
| 89 |
-
|
| 90 |
-
— *end note*]
|
| 91 |
|
| 92 |
A *type-constraint* `Q` that designates a concept `C` can be used to
|
| 93 |
constrain a contextually-determined type or template type parameter pack
|
| 94 |
`T` with a *constraint-expression* `E` defined as follows. If `Q` is of
|
| 95 |
-
the form `C<A₁,
|
| 96 |
let `E'` be `C<T>`. If `T` is not a pack, then `E` is `E'`, otherwise
|
| 97 |
`E` is `(E' && ...)`. This *constraint-expression* `E` is called the
|
| 98 |
*immediately-declared constraint* of `Q` for `T`. The concept designated
|
| 99 |
by a *type-constraint* shall be a type concept [[temp.concept]].
|
| 100 |
|
| 101 |
A *type-parameter* that starts with a *type-constraint* introduces the
|
| 102 |
immediately-declared constraint of the *type-constraint* for the
|
| 103 |
parameter.
|
| 104 |
|
| 105 |
-
[*Example
|
| 106 |
|
| 107 |
``` cpp
|
| 108 |
template<typename T> concept C1 = true;
|
| 109 |
template<typename... Ts> concept C2 = true;
|
| 110 |
template<typename T, typename U> concept C3 = true;
|
|
@@ -116,12 +184,12 @@ template<C3<int> T> struct s4; // associates C3<T, int>
|
|
| 116 |
template<C3<int>... T> struct s5; // associates (C3<T, int> && ...)
|
| 117 |
```
|
| 118 |
|
| 119 |
— *end example*]
|
| 120 |
|
| 121 |
-
A
|
| 122 |
-
|
| 123 |
|
| 124 |
- a structural type (see below),
|
| 125 |
- a type that contains a placeholder type [[dcl.spec.auto]], or
|
| 126 |
- a placeholder for a deduced class type [[dcl.type.class.deduct]].
|
| 127 |
|
|
@@ -133,66 +201,63 @@ A *structural type* is one of the following:
|
|
| 133 |
- a scalar type, or
|
| 134 |
- an lvalue reference type, or
|
| 135 |
- a literal class type with the following properties:
|
| 136 |
- all base classes and non-static data members are public and
|
| 137 |
non-mutable and
|
| 138 |
-
- the types of all
|
| 139 |
-
structural types or (possibly multidimensional)
|
| 140 |
|
| 141 |
-
An *id-expression* naming a
|
| 142 |
`T` denotes a static storage duration object of type `const T`, known as
|
| 143 |
-
a *template parameter object*,
|
| 144 |
-
template argument after it has been
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
A template parameter object shall have constant destruction
|
| 148 |
-
[[expr.const]].
|
| 149 |
|
| 150 |
-
[*Note
|
| 151 |
-
|
| 152 |
Otherwise, if it is of class type `T`, it is an lvalue and has type
|
| 153 |
`const T` [[expr.prim.id.unqual]]. — *end note*]
|
| 154 |
|
| 155 |
-
[*Example
|
| 156 |
|
| 157 |
``` cpp
|
| 158 |
using X = int;
|
| 159 |
struct A {};
|
| 160 |
template<const X& x, int i, A a> void f() {
|
| 161 |
-
i++; // error: change of template
|
| 162 |
|
| 163 |
&x; // OK
|
| 164 |
-
&i; // error: address of non-reference template
|
| 165 |
&a; // OK
|
| 166 |
int& ri = i; // error: attempt to bind non-const reference to temporary
|
| 167 |
const int& cri = i; // OK, const reference binds to temporary
|
| 168 |
const A& ra = a; // OK, const reference binds to a template parameter object
|
| 169 |
}
|
| 170 |
```
|
| 171 |
|
| 172 |
— *end example*]
|
| 173 |
|
| 174 |
-
[*Note
|
| 175 |
|
| 176 |
-
A
|
| 177 |
-
`void`.
|
| 178 |
|
| 179 |
-
[*Example
|
| 180 |
|
| 181 |
``` cpp
|
| 182 |
template<void v> class X; // error
|
| 183 |
template<void* pv> class Y; // OK
|
| 184 |
```
|
| 185 |
|
| 186 |
— *end example*]
|
| 187 |
|
| 188 |
— *end note*]
|
| 189 |
|
| 190 |
-
A
|
| 191 |
-
|
| 192 |
|
| 193 |
-
[*Example
|
| 194 |
|
| 195 |
``` cpp
|
| 196 |
template<int* a> struct R { ... };
|
| 197 |
template<int b[5]> struct S { ... };
|
| 198 |
int p;
|
|
@@ -203,35 +268,35 @@ R<v> y; // OK due to implicit argument conversion
|
|
| 203 |
S<v> z; // OK due to both adjustment and conversion
|
| 204 |
```
|
| 205 |
|
| 206 |
— *end example*]
|
| 207 |
|
| 208 |
-
A
|
| 209 |
placeholder type with a *type-constraint* introduces the
|
| 210 |
immediately-declared constraint of the *type-constraint* for the
|
| 211 |
invented type corresponding to the placeholder [[dcl.fct]].
|
| 212 |
|
| 213 |
-
A *default template
|
| 214 |
-
specified after `=` in a *template-parameter*. A default
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
|
| 227 |
-
The set of default
|
| 228 |
merging the default arguments from all prior declarations of the
|
| 229 |
template in the same way default function arguments are
|
| 230 |
[[dcl.fct.default]].
|
| 231 |
|
| 232 |
-
[*Example
|
| 233 |
|
| 234 |
``` cpp
|
| 235 |
template<class T1, class T2 = int> class A;
|
| 236 |
template<class T1 = int, class T2> class A;
|
| 237 |
```
|
|
@@ -243,24 +308,25 @@ template<class T1 = int, class T2 = int> class A;
|
|
| 243 |
```
|
| 244 |
|
| 245 |
— *end example*]
|
| 246 |
|
| 247 |
If a *template-parameter* of a class template, variable template, or
|
| 248 |
-
alias template has a default
|
| 249 |
-
*template-parameter* shall either have a default
|
| 250 |
-
supplied or
|
| 251 |
-
primary class template, primary variable template, or alias
|
| 252 |
-
a template parameter pack, it shall be the last
|
| 253 |
-
template
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
|
|
|
| 257 |
guide template [[temp.deduct.guide]] that does not have a default
|
| 258 |
argument shall be deducible from the parameter-type-list of the
|
| 259 |
deduction guide template.
|
| 260 |
|
| 261 |
-
[*Example
|
| 262 |
|
| 263 |
``` cpp
|
| 264 |
template<class T1 = int, class T2> class B; // error
|
| 265 |
|
| 266 |
// U can be neither deduced from the parameter-type-list nor specified
|
|
@@ -268,15 +334,15 @@ template<class... T, class... U> void f() { } // error
|
|
| 268 |
template<class... T, class U> void g() { } // error
|
| 269 |
```
|
| 270 |
|
| 271 |
— *end example*]
|
| 272 |
|
| 273 |
-
When parsing a default
|
| 274 |
-
|
| 275 |
-
|
| 276 |
|
| 277 |
-
[*Example
|
| 278 |
|
| 279 |
``` cpp
|
| 280 |
template<int i = 3 > 4 > // syntax error
|
| 281 |
class X { ... };
|
| 282 |
|
|
@@ -285,15 +351,15 @@ class Y { ... };
|
|
| 285 |
```
|
| 286 |
|
| 287 |
— *end example*]
|
| 288 |
|
| 289 |
A *template-parameter* of a template *template-parameter* is permitted
|
| 290 |
-
to have a default
|
| 291 |
specified, they apply to the template *template-parameter* in the scope
|
| 292 |
of the template *template-parameter*.
|
| 293 |
|
| 294 |
-
[*Example
|
| 295 |
|
| 296 |
``` cpp
|
| 297 |
template <template <class TT = float> class T> struct A {
|
| 298 |
inline void f();
|
| 299 |
inline void g();
|
|
@@ -306,38 +372,20 @@ template <template <class TT = char> class T> void A<T>::g() {
|
|
| 306 |
}
|
| 307 |
```
|
| 308 |
|
| 309 |
— *end example*]
|
| 310 |
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
declares a pack [[dcl.fct]], then the *template-parameter* is a template
|
| 314 |
-
parameter pack [[temp.variadic]]. A template parameter pack that is a
|
| 315 |
-
*parameter-declaration* whose type contains one or more unexpanded packs
|
| 316 |
-
is a pack expansion. Similarly, a template parameter pack that is a
|
| 317 |
-
*type-parameter* with a *template-parameter-list* containing one or more
|
| 318 |
-
unexpanded packs is a pack expansion. A type parameter pack with a
|
| 319 |
-
*type-constraint* that contains an unexpanded parameter pack is a pack
|
| 320 |
-
expansion. A template parameter pack that is a pack expansion shall not
|
| 321 |
-
expand a template parameter pack declared in the same
|
| 322 |
-
*template-parameter-list*.
|
| 323 |
|
| 324 |
-
[*Example
|
| 325 |
|
| 326 |
``` cpp
|
| 327 |
-
template
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
template <class... T>
|
| 334 |
-
struct value_holder {
|
| 335 |
-
template <T... Values> struct apply { }; // Values is a non-type template parameter pack
|
| 336 |
-
}; // and a pack expansion
|
| 337 |
-
|
| 338 |
-
template <class... T, T... Values> // error: Values expands template type parameter
|
| 339 |
-
struct static_array; // pack T within the same template parameter list
|
| 340 |
```
|
| 341 |
|
| 342 |
— *end example*]
|
| 343 |
|
|
|
|
| 4 |
|
| 5 |
``` bnf
|
| 6 |
template-parameter:
|
| 7 |
type-parameter
|
| 8 |
parameter-declaration
|
| 9 |
+
type-tt-parameter
|
| 10 |
+
variable-tt-parameter
|
| 11 |
+
concept-tt-parameter
|
| 12 |
```
|
| 13 |
|
| 14 |
``` bnf
|
| 15 |
type-parameter:
|
| 16 |
type-parameter-key '...'ₒₚₜ identifierₒₚₜ
|
| 17 |
type-parameter-key identifierₒₚₜ '=' type-id
|
| 18 |
type-constraint '...'ₒₚₜ identifierₒₚₜ
|
| 19 |
type-constraint identifierₒₚₜ '=' type-id
|
|
|
|
|
|
|
| 20 |
```
|
| 21 |
|
| 22 |
``` bnf
|
| 23 |
type-parameter-key:
|
| 24 |
class
|
|
|
|
| 29 |
type-constraint:
|
| 30 |
nested-name-specifierₒₚₜ concept-name
|
| 31 |
nested-name-specifierₒₚₜ concept-name '<' template-argument-listₒₚₜ '>'
|
| 32 |
```
|
| 33 |
|
| 34 |
+
``` bnf
|
| 35 |
+
type-tt-parameter:
|
| 36 |
+
template-head type-parameter-key '...'ₒₚₜ identifierₒₚₜ
|
| 37 |
+
template-head type-parameter-key identifierₒₚₜ type-tt-parameter-default
|
| 38 |
+
```
|
| 39 |
+
|
| 40 |
+
``` bnf
|
| 41 |
+
type-tt-parameter-default:
|
| 42 |
+
'=' nested-name-specifierₒₚₜ template-name
|
| 43 |
+
'=' nested-name-specifier 'template' template-name
|
| 44 |
+
```
|
| 45 |
+
|
| 46 |
+
``` bnf
|
| 47 |
+
variable-tt-parameter:
|
| 48 |
+
template-head 'auto' '...'ₒₚₜ identifierₒₚₜ
|
| 49 |
+
template-head 'auto' identifierₒₚₜ '=' nested-name-specifierₒₚₜ template-name
|
| 50 |
+
```
|
| 51 |
+
|
| 52 |
+
``` bnf
|
| 53 |
+
concept-tt-parameter:
|
| 54 |
+
'template' '<' template-parameter-list '>' 'concept' '...'ₒₚₜ identifierₒₚₜ
|
| 55 |
+
'template' '<' template-parameter-list '>' 'concept' identifierₒₚₜ '=' nested-name-specifierₒₚₜ template-name
|
| 56 |
+
```
|
| 57 |
+
|
| 58 |
The component names of a *type-constraint* are its *concept-name* and
|
| 59 |
those of its *nested-name-specifier* (if any).
|
| 60 |
|
| 61 |
[*Note 1*: The `>` token following the *template-parameter-list* of a
|
| 62 |
+
*type-tt-parameter*, *variable-tt-parameter*, or *concept-tt-parameter*
|
| 63 |
+
can be the product of replacing a `>>` token by two consecutive `>`
|
| 64 |
+
tokens [[temp.names]]. — *end note*]
|
| 65 |
+
|
| 66 |
+
A template parameter is of one of the following kinds:
|
| 67 |
+
|
| 68 |
+
- A *type template parameter* is a template parameter introduced by a
|
| 69 |
+
*type-parameter*.
|
| 70 |
+
- A *constant template parameter* is a template parameter introduced by
|
| 71 |
+
a *parameter-declaration*.
|
| 72 |
+
- A *type template template parameter* is a template parameter
|
| 73 |
+
introduced by a *type-tt-parameter*.
|
| 74 |
+
- A *variable template template parameter* is a template parameter
|
| 75 |
+
introduced by a *variable-tt-parameter*.
|
| 76 |
+
- A *concept template parameter* is a template parameter introduced by a
|
| 77 |
+
*concept-tt-parameter*.
|
| 78 |
+
|
| 79 |
+
Type template template parameters, variable template template
|
| 80 |
+
parameters, and concept template parameters are collectively referred to
|
| 81 |
+
as *template template parameters*.
|
| 82 |
+
|
| 83 |
+
The *nested-name-specifier* of a *type-constraint*, if any, shall not be
|
| 84 |
+
dependent.
|
| 85 |
+
|
| 86 |
+
A concept template parameter shall not have associated constraints
|
| 87 |
+
[[temp.constr.decl]].
|
| 88 |
+
|
| 89 |
+
If a *template-parameter* is a *parameter-declaration* that declares a
|
| 90 |
+
pack [[dcl.fct]], or otherwise has an ellipsis prior to its optional
|
| 91 |
+
*identifier*, then the *template-parameter* declares a template
|
| 92 |
+
parameter pack [[temp.variadic]]. A template parameter pack that is a
|
| 93 |
+
*parameter-declaration* whose type contains one or more unexpanded packs
|
| 94 |
+
is a pack expansion. Similarly, a template parameter pack that is a
|
| 95 |
+
template template parameter with a *template-parameter-list* containing
|
| 96 |
+
one or more unexpanded packs is a pack expansion. A type parameter pack
|
| 97 |
+
with a *type-constraint* that contains an unexpanded parameter pack is a
|
| 98 |
+
pack expansion. A template parameter pack that is a pack expansion shall
|
| 99 |
+
not expand a template parameter pack declared in the same
|
| 100 |
+
*template-parameter-list*.
|
| 101 |
+
|
| 102 |
+
[*Example 1*:
|
| 103 |
+
|
| 104 |
+
``` cpp
|
| 105 |
+
template <class... Types> // Types is a template type parameter pack
|
| 106 |
+
class Tuple; // but not a pack expansion
|
| 107 |
+
|
| 108 |
+
template <class T, int... Dims> // Dims is a constant template parameter pack
|
| 109 |
+
struct multi_array; // but not a pack expansion
|
| 110 |
+
|
| 111 |
+
template <class... T>
|
| 112 |
+
struct value_holder {
|
| 113 |
+
template <T... Values> struct apply { }; // Values is a constant template parameter pack
|
| 114 |
+
}; // and a pack expansion
|
| 115 |
+
|
| 116 |
+
template <class... T, T... Values> // error: Values expands template type parameter
|
| 117 |
+
struct static_array; // pack T within the same template parameter list
|
| 118 |
+
```
|
| 119 |
+
|
| 120 |
+
— *end example*]
|
| 121 |
|
| 122 |
There is no semantic difference between `class` and `typename` in a
|
| 123 |
*type-parameter-key*. `typename` followed by an *unqualified-id* names a
|
| 124 |
template type parameter. `typename` followed by a *qualified-id* denotes
|
| 125 |
+
the type in a *parameter-declaration*. A *template-parameter* of the
|
| 126 |
+
form `class` *identifier* is a *type-parameter*.
|
| 127 |
|
| 128 |
+
[*Example 2*:
|
|
|
|
|
|
|
|
|
|
| 129 |
|
| 130 |
``` cpp
|
| 131 |
class T { ... };
|
| 132 |
int i;
|
| 133 |
|
| 134 |
template<class T, T i> void f(T t) {
|
| 135 |
+
T t1 = i; // template parameters T and i
|
| 136 |
::T t2 = ::i; // global namespace members T and i
|
| 137 |
}
|
| 138 |
```
|
| 139 |
|
| 140 |
+
Here, the template `f` has a type template parameter called `T`, rather
|
| 141 |
+
than an unnamed constant template parameter of class `T`.
|
| 142 |
|
| 143 |
— *end example*]
|
| 144 |
|
| 145 |
+
The *parameter-declaration* of a *template-parameter* shall not have a
|
| 146 |
+
*storage-class-specifier*. Types shall not be defined in a template
|
| 147 |
+
parameter declaration.
|
| 148 |
|
| 149 |
+
The *identifier* in a *template-parameter* denoting a type or template
|
| 150 |
+
is not looked up. An *identifier* that does not follow an ellipsis is
|
| 151 |
+
defined to be
|
|
|
|
|
|
|
| 152 |
|
| 153 |
+
- a *typedef-name* for a *type-parameter*,
|
| 154 |
+
- a *template-name* for a *variable-tt-parameter*,
|
| 155 |
+
- a *template-name* for a *type-tt-parameter*, or
|
| 156 |
+
- a *concept-name* for a *concept-tt-parameter*,
|
| 157 |
|
| 158 |
+
in the scope of the template declaration.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
|
| 160 |
A *type-constraint* `Q` that designates a concept `C` can be used to
|
| 161 |
constrain a contextually-determined type or template type parameter pack
|
| 162 |
`T` with a *constraint-expression* `E` defined as follows. If `Q` is of
|
| 163 |
+
the form `C<A₁, …, Aₙ>`, then let `E'` be `C<T, A₁, …, Aₙ>`. Otherwise,
|
| 164 |
let `E'` be `C<T>`. If `T` is not a pack, then `E` is `E'`, otherwise
|
| 165 |
`E` is `(E' && ...)`. This *constraint-expression* `E` is called the
|
| 166 |
*immediately-declared constraint* of `Q` for `T`. The concept designated
|
| 167 |
by a *type-constraint* shall be a type concept [[temp.concept]].
|
| 168 |
|
| 169 |
A *type-parameter* that starts with a *type-constraint* introduces the
|
| 170 |
immediately-declared constraint of the *type-constraint* for the
|
| 171 |
parameter.
|
| 172 |
|
| 173 |
+
[*Example 3*:
|
| 174 |
|
| 175 |
``` cpp
|
| 176 |
template<typename T> concept C1 = true;
|
| 177 |
template<typename... Ts> concept C2 = true;
|
| 178 |
template<typename T, typename U> concept C3 = true;
|
|
|
|
| 184 |
template<C3<int>... T> struct s5; // associates (C3<T, int> && ...)
|
| 185 |
```
|
| 186 |
|
| 187 |
— *end example*]
|
| 188 |
|
| 189 |
+
A constant template parameter shall have one of the following (possibly
|
| 190 |
+
cv-qualified) types:
|
| 191 |
|
| 192 |
- a structural type (see below),
|
| 193 |
- a type that contains a placeholder type [[dcl.spec.auto]], or
|
| 194 |
- a placeholder for a deduced class type [[dcl.type.class.deduct]].
|
| 195 |
|
|
|
|
| 201 |
- a scalar type, or
|
| 202 |
- an lvalue reference type, or
|
| 203 |
- a literal class type with the following properties:
|
| 204 |
- all base classes and non-static data members are public and
|
| 205 |
non-mutable and
|
| 206 |
+
- the types of all base classes and non-static data members are
|
| 207 |
+
structural types or (possibly multidimensional) arrays thereof.
|
| 208 |
|
| 209 |
+
An *id-expression* naming a constant template parameter of class type
|
| 210 |
`T` denotes a static storage duration object of type `const T`, known as
|
| 211 |
+
a *template parameter object*, which is template-argument-equivalent
|
| 212 |
+
[[temp.type]] to the corresponding template argument after it has been
|
| 213 |
+
converted to the type of the template parameter [[temp.arg.nontype]]. No
|
| 214 |
+
two template parameter objects are template-argument-equivalent.
|
|
|
|
|
|
|
| 215 |
|
| 216 |
+
[*Note 2*: If an *id-expression* names a non-reference constant
|
| 217 |
+
template parameter, then it is a prvalue if it has non-class type.
|
| 218 |
Otherwise, if it is of class type `T`, it is an lvalue and has type
|
| 219 |
`const T` [[expr.prim.id.unqual]]. — *end note*]
|
| 220 |
|
| 221 |
+
[*Example 4*:
|
| 222 |
|
| 223 |
``` cpp
|
| 224 |
using X = int;
|
| 225 |
struct A {};
|
| 226 |
template<const X& x, int i, A a> void f() {
|
| 227 |
+
i++; // error: change of template parameter value
|
| 228 |
|
| 229 |
&x; // OK
|
| 230 |
+
&i; // error: address of non-reference template parameter
|
| 231 |
&a; // OK
|
| 232 |
int& ri = i; // error: attempt to bind non-const reference to temporary
|
| 233 |
const int& cri = i; // OK, const reference binds to temporary
|
| 234 |
const A& ra = a; // OK, const reference binds to a template parameter object
|
| 235 |
}
|
| 236 |
```
|
| 237 |
|
| 238 |
— *end example*]
|
| 239 |
|
| 240 |
+
[*Note 3*:
|
| 241 |
|
| 242 |
+
A constant template parameter cannot be declared to have type cv `void`.
|
|
|
|
| 243 |
|
| 244 |
+
[*Example 5*:
|
| 245 |
|
| 246 |
``` cpp
|
| 247 |
template<void v> class X; // error
|
| 248 |
template<void* pv> class Y; // OK
|
| 249 |
```
|
| 250 |
|
| 251 |
— *end example*]
|
| 252 |
|
| 253 |
— *end note*]
|
| 254 |
|
| 255 |
+
A constant template parameter of type “array of `T`” or of function type
|
| 256 |
+
`T` is adjusted to be of type “pointer to `T`”.
|
| 257 |
|
| 258 |
+
[*Example 6*:
|
| 259 |
|
| 260 |
``` cpp
|
| 261 |
template<int* a> struct R { ... };
|
| 262 |
template<int b[5]> struct S { ... };
|
| 263 |
int p;
|
|
|
|
| 268 |
S<v> z; // OK due to both adjustment and conversion
|
| 269 |
```
|
| 270 |
|
| 271 |
— *end example*]
|
| 272 |
|
| 273 |
+
A constant template parameter declared with a type that contains a
|
| 274 |
placeholder type with a *type-constraint* introduces the
|
| 275 |
immediately-declared constraint of the *type-constraint* for the
|
| 276 |
invented type corresponding to the placeholder [[dcl.fct]].
|
| 277 |
|
| 278 |
+
A *default template argument* is a template argument [[temp.arg]]
|
| 279 |
+
specified after `=` in a *template-parameter*. A default template
|
| 280 |
+
argument may be specified for any kind of template parameter that is not
|
| 281 |
+
a template parameter pack [[temp.variadic]]. A default template argument
|
| 282 |
+
may be specified in a template declaration. A default template argument
|
| 283 |
+
shall not be specified in the *template-parameter-list*s of the
|
| 284 |
+
definition of a member of a class template that appears outside of the
|
| 285 |
+
member’s class. A default template argument shall not be specified in a
|
| 286 |
+
friend class template declaration. If a friend function template
|
| 287 |
+
declaration D specifies a default template argument, that declaration
|
| 288 |
+
shall be a definition and there shall be no other declaration of the
|
| 289 |
+
function template which is reachable from D or from which D is
|
| 290 |
+
reachable.
|
| 291 |
|
| 292 |
+
The set of default template arguments available for use is obtained by
|
| 293 |
merging the default arguments from all prior declarations of the
|
| 294 |
template in the same way default function arguments are
|
| 295 |
[[dcl.fct.default]].
|
| 296 |
|
| 297 |
+
[*Example 7*:
|
| 298 |
|
| 299 |
``` cpp
|
| 300 |
template<class T1, class T2 = int> class A;
|
| 301 |
template<class T1 = int, class T2> class A;
|
| 302 |
```
|
|
|
|
| 308 |
```
|
| 309 |
|
| 310 |
— *end example*]
|
| 311 |
|
| 312 |
If a *template-parameter* of a class template, variable template, or
|
| 313 |
+
alias template has a default template argument, each subsequent
|
| 314 |
+
*template-parameter* shall either have a default template argument
|
| 315 |
+
supplied or declare a template parameter pack. If a *template-parameter*
|
| 316 |
+
of a primary class template, primary variable template, or alias
|
| 317 |
+
template declares a template parameter pack, it shall be the last
|
| 318 |
+
*template-parameter*. If a *template-parameter* of a function template
|
| 319 |
+
declares a template parameter pack, it shall not be followed by another
|
| 320 |
+
*template-parameter* unless that template parameter is deducible from
|
| 321 |
+
the parameter-type-list [[dcl.fct]] of the function template or has a
|
| 322 |
+
default argument [[temp.deduct]]. A template parameter of a deduction
|
| 323 |
guide template [[temp.deduct.guide]] that does not have a default
|
| 324 |
argument shall be deducible from the parameter-type-list of the
|
| 325 |
deduction guide template.
|
| 326 |
|
| 327 |
+
[*Example 8*:
|
| 328 |
|
| 329 |
``` cpp
|
| 330 |
template<class T1 = int, class T2> class B; // error
|
| 331 |
|
| 332 |
// U can be neither deduced from the parameter-type-list nor specified
|
|
|
|
| 334 |
template<class... T, class U> void g() { } // error
|
| 335 |
```
|
| 336 |
|
| 337 |
— *end example*]
|
| 338 |
|
| 339 |
+
When parsing a default template argument for a constant template
|
| 340 |
+
parameter, the first non-nested `>` is taken as the end of the
|
| 341 |
+
*template-parameter-list* rather than a greater-than operator.
|
| 342 |
|
| 343 |
+
[*Example 9*:
|
| 344 |
|
| 345 |
``` cpp
|
| 346 |
template<int i = 3 > 4 > // syntax error
|
| 347 |
class X { ... };
|
| 348 |
|
|
|
|
| 351 |
```
|
| 352 |
|
| 353 |
— *end example*]
|
| 354 |
|
| 355 |
A *template-parameter* of a template *template-parameter* is permitted
|
| 356 |
+
to have a default template argument. When such default arguments are
|
| 357 |
specified, they apply to the template *template-parameter* in the scope
|
| 358 |
of the template *template-parameter*.
|
| 359 |
|
| 360 |
+
[*Example 10*:
|
| 361 |
|
| 362 |
``` cpp
|
| 363 |
template <template <class TT = float> class T> struct A {
|
| 364 |
inline void f();
|
| 365 |
inline void g();
|
|
|
|
| 372 |
}
|
| 373 |
```
|
| 374 |
|
| 375 |
— *end example*]
|
| 376 |
|
| 377 |
+
The associated constraints of a template template parameter shall not
|
| 378 |
+
contain a concept-dependent constraint [[temp.constr.concept]].
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 379 |
|
| 380 |
+
[*Example 11*:
|
| 381 |
|
| 382 |
``` cpp
|
| 383 |
+
template<
|
| 384 |
+
template<typename> concept C,
|
| 385 |
+
template<C> class TT // error: C forms a concept-dependent constraint
|
| 386 |
+
>
|
| 387 |
+
struct A {};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 388 |
```
|
| 389 |
|
| 390 |
— *end example*]
|
| 391 |
|