tmp/tmpjcz5ufbi/{from.md → to.md}
RENAMED
|
@@ -31,41 +31,60 @@ template-argument:
|
|
| 31 |
constant-expression
|
| 32 |
type-id
|
| 33 |
id-expression
|
| 34 |
```
|
| 35 |
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
distinct `>` tokens, the first of which is taken as the end of the
|
| 60 |
*template-argument-list* and completes the *template-id*.
|
| 61 |
|
| 62 |
-
[*Note
|
| 63 |
-
terminate an enclosing *template-id* construct or it
|
| 64 |
different construct (e.g., a cast). — *end note*]
|
| 65 |
|
| 66 |
-
[*Example
|
| 67 |
|
| 68 |
``` cpp
|
| 69 |
template<int i> class X { ... };
|
| 70 |
|
| 71 |
X< 1>2 > x1; // syntax error
|
|
@@ -77,53 +96,25 @@ Y<X<6>>1>> x4; // syntax error
|
|
| 77 |
Y<X<(6>>1)>> x5; // OK
|
| 78 |
```
|
| 79 |
|
| 80 |
— *end example*]
|
| 81 |
|
| 82 |
-
The keyword `template`
|
| 83 |
-
*
|
| 84 |
-
*decltype-specifier*. In a *qualified-id* of a *declarator-id* or in a
|
| 85 |
-
*qualified-id* formed by a *class-head-name* [[class.pre]] or
|
| 86 |
-
*enum-head-name* [[dcl.enum]], the keyword `template` shall not appear
|
| 87 |
-
at the top level. In a *qualified-id* used as the name in a
|
| 88 |
-
*typename-specifier* [[temp.res]], *elaborated-type-specifier*
|
| 89 |
-
[[dcl.type.elab]], *using-declaration* [[namespace.udecl]], or
|
| 90 |
-
*class-or-decltype* [[class.derived]], an optional keyword `template`
|
| 91 |
-
appearing at the top level is ignored. In these contexts, a `<` token is
|
| 92 |
-
always assumed to introduce a *template-argument-list*. In all other
|
| 93 |
-
contexts, when naming a template specialization of a member of an
|
| 94 |
-
unknown specialization [[temp.dep.type]], the member template name shall
|
| 95 |
-
be prefixed by the keyword `template`.
|
| 96 |
|
| 97 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
|
| 99 |
-
``
|
| 100 |
-
struct X {
|
| 101 |
-
template<std::size_t> X* alloc();
|
| 102 |
-
template<std::size_t> static X* adjust();
|
| 103 |
-
};
|
| 104 |
-
template<class T> void f(T* p) {
|
| 105 |
-
T* p1 = p->alloc<200>(); // error: < means less than
|
| 106 |
-
T* p2 = p->template alloc<200>(); // OK: < starts template argument list
|
| 107 |
-
T::adjust<100>(); // error: < means less than
|
| 108 |
-
T::template adjust<100>(); // OK: < starts template argument list
|
| 109 |
-
}
|
| 110 |
-
```
|
| 111 |
-
|
| 112 |
-
— *end example*]
|
| 113 |
-
|
| 114 |
-
A name prefixed by the keyword `template` shall be a *template-id* or
|
| 115 |
-
the name shall refer to a class template or an alias template.
|
| 116 |
-
|
| 117 |
-
[*Note 4*: The keyword `template` may not be applied to non-template
|
| 118 |
members of class templates. — *end note*]
|
| 119 |
|
| 120 |
-
[*Note
|
| 121 |
-
prefix is allowed
|
| 122 |
-
|
| 123 |
-
`->` or `.` is not dependent on a *template-parameter*, or the use does
|
| 124 |
-
not appear in the scope of a template. — *end note*]
|
| 125 |
|
| 126 |
[*Example 3*:
|
| 127 |
|
| 128 |
``` cpp
|
| 129 |
template <class T> struct A {
|
|
@@ -131,19 +122,19 @@ template <class T> struct A {
|
|
| 131 |
template <class U> void f(U);
|
| 132 |
};
|
| 133 |
|
| 134 |
template <class T> void f(T t) {
|
| 135 |
A<T> a;
|
| 136 |
-
a.template f<>(t); // OK
|
| 137 |
a.template f(t); // error: not a template-id
|
| 138 |
}
|
| 139 |
|
| 140 |
template <class T> struct B {
|
| 141 |
template <class T2> struct C { };
|
| 142 |
};
|
| 143 |
|
| 144 |
-
//
|
| 145 |
template <class T, template <class X> class TT = T::template C> struct D { };
|
| 146 |
D<B<int> > db;
|
| 147 |
```
|
| 148 |
|
| 149 |
— *end example*]
|
|
@@ -180,13 +171,12 @@ using T5 = X<S>; // OK
|
|
| 180 |
|
| 181 |
— *end example*]
|
| 182 |
|
| 183 |
When the *template-name* of a *simple-template-id* names a constrained
|
| 184 |
non-function template or a constrained template *template-parameter*,
|
| 185 |
-
|
| 186 |
-
[[temp.
|
| 187 |
-
are non-dependent [[temp.dep.temp]], the associated constraints
|
| 188 |
[[temp.constr.decl]] of the constrained template shall be satisfied
|
| 189 |
[[temp.constr.constr]].
|
| 190 |
|
| 191 |
[*Example 5*:
|
| 192 |
|
|
@@ -227,11 +217,11 @@ A *concept-id* is a *simple-template-id* where the *template-name* is a
|
|
| 227 |
name a template specialization. A concept-id evaluates to `true` if the
|
| 228 |
concept’s normalized *constraint-expression* [[temp.constr.decl]] is
|
| 229 |
satisfied [[temp.constr.constr]] by the specified template arguments and
|
| 230 |
`false` otherwise.
|
| 231 |
|
| 232 |
-
[*Note
|
| 233 |
concept-id appearing in a *constraint-expression* is not evaluated
|
| 234 |
except as necessary to determine whether the normalized constraints are
|
| 235 |
satisfied. — *end note*]
|
| 236 |
|
| 237 |
[*Example 6*:
|
|
|
|
| 31 |
constant-expression
|
| 32 |
type-id
|
| 33 |
id-expression
|
| 34 |
```
|
| 35 |
|
| 36 |
+
The component name of a *simple-template-id*, *template-id*, or
|
| 37 |
+
*template-name* is the first name in it.
|
| 38 |
+
|
| 39 |
+
A `<` is interpreted as the delimiter of a *template-argument-list* if
|
| 40 |
+
it follows a name that is not a *conversion-function-id* and
|
| 41 |
+
|
| 42 |
+
- that follows the keyword `template` or a `~` after a
|
| 43 |
+
*nested-name-specifier* or in a class member access expression, or
|
| 44 |
+
- for which name lookup finds the injected-class-name of a class
|
| 45 |
+
template or finds any declaration of a template, or
|
| 46 |
+
- that is an unqualified name for which name lookup either finds one or
|
| 47 |
+
more functions or finds nothing, or
|
| 48 |
+
- that is a terminal name in a *using-declarator* [[namespace.udecl]],
|
| 49 |
+
in a *declarator-id* [[dcl.meaning]], or in a type-only context other
|
| 50 |
+
than a *nested-name-specifier* [[temp.res]].
|
| 51 |
+
|
| 52 |
+
[*Note 1*: If the name is an *identifier*, it is then interpreted as a
|
| 53 |
+
*template-name*. The keyword `template` is used to indicate that a
|
| 54 |
+
dependent qualified name [[temp.dep.type]] denotes a template where an
|
| 55 |
+
expression might appear. — *end note*]
|
| 56 |
+
|
| 57 |
+
[*Example 1*:
|
| 58 |
+
|
| 59 |
+
``` cpp
|
| 60 |
+
struct X {
|
| 61 |
+
template<std::size_t> X* alloc();
|
| 62 |
+
template<std::size_t> static X* adjust();
|
| 63 |
+
};
|
| 64 |
+
template<class T> void f(T* p) {
|
| 65 |
+
T* p1 = p->alloc<200>(); // error: < means less than
|
| 66 |
+
T* p2 = p->template alloc<200>(); // OK, < starts template argument list
|
| 67 |
+
T::adjust<100>(); // error: < means less than
|
| 68 |
+
T::template adjust<100>(); // OK, < starts template argument list
|
| 69 |
+
}
|
| 70 |
+
```
|
| 71 |
+
|
| 72 |
+
— *end example*]
|
| 73 |
+
|
| 74 |
+
When parsing a *template-argument-list*, the first non-nested `>`[^2]
|
| 75 |
+
|
| 76 |
+
is taken as the ending delimiter rather than a greater-than operator.
|
| 77 |
+
Similarly, the first non-nested `>>` is treated as two consecutive but
|
| 78 |
distinct `>` tokens, the first of which is taken as the end of the
|
| 79 |
*template-argument-list* and completes the *template-id*.
|
| 80 |
|
| 81 |
+
[*Note 2*: The second `>` token produced by this replacement rule can
|
| 82 |
+
terminate an enclosing *template-id* construct or it can be part of a
|
| 83 |
different construct (e.g., a cast). — *end note*]
|
| 84 |
|
| 85 |
+
[*Example 2*:
|
| 86 |
|
| 87 |
``` cpp
|
| 88 |
template<int i> class X { ... };
|
| 89 |
|
| 90 |
X< 1>2 > x1; // syntax error
|
|
|
|
| 96 |
Y<X<(6>>1)>> x5; // OK
|
| 97 |
```
|
| 98 |
|
| 99 |
— *end example*]
|
| 100 |
|
| 101 |
+
The keyword `template` shall not appear immediately after a declarative
|
| 102 |
+
*nested-name-specifier* [[expr.prim.id.qual]].
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
|
| 104 |
+
A name prefixed by the keyword `template` shall be followed by a
|
| 105 |
+
template argument list or refer to a class template or an alias
|
| 106 |
+
template. The latter case is deprecated [[depr.template.template]]. The
|
| 107 |
+
keyword `template` shall not appear immediately before a `~` token (as
|
| 108 |
+
to name a destructor).
|
| 109 |
|
| 110 |
+
[*Note 3*: The keyword `template` cannot be applied to non-template
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
members of class templates. — *end note*]
|
| 112 |
|
| 113 |
+
[*Note 4*: As is the case with the `typename` prefix, the `template`
|
| 114 |
+
prefix is allowed even when lookup for the name would already find a
|
| 115 |
+
template. — *end note*]
|
|
|
|
|
|
|
| 116 |
|
| 117 |
[*Example 3*:
|
| 118 |
|
| 119 |
``` cpp
|
| 120 |
template <class T> struct A {
|
|
|
|
| 122 |
template <class U> void f(U);
|
| 123 |
};
|
| 124 |
|
| 125 |
template <class T> void f(T t) {
|
| 126 |
A<T> a;
|
| 127 |
+
a.template f<>(t); // OK, calls template
|
| 128 |
a.template f(t); // error: not a template-id
|
| 129 |
}
|
| 130 |
|
| 131 |
template <class T> struct B {
|
| 132 |
template <class T2> struct C { };
|
| 133 |
};
|
| 134 |
|
| 135 |
+
// deprecated: T::C is assumed to name a class template:
|
| 136 |
template <class T, template <class X> class TT = T::template C> struct D { };
|
| 137 |
D<B<int> > db;
|
| 138 |
```
|
| 139 |
|
| 140 |
— *end example*]
|
|
|
|
| 171 |
|
| 172 |
— *end example*]
|
| 173 |
|
| 174 |
When the *template-name* of a *simple-template-id* names a constrained
|
| 175 |
non-function template or a constrained template *template-parameter*,
|
| 176 |
+
and all *template-argument*s in the *simple-template-id* are
|
| 177 |
+
non-dependent [[temp.dep.temp]], the associated constraints
|
|
|
|
| 178 |
[[temp.constr.decl]] of the constrained template shall be satisfied
|
| 179 |
[[temp.constr.constr]].
|
| 180 |
|
| 181 |
[*Example 5*:
|
| 182 |
|
|
|
|
| 217 |
name a template specialization. A concept-id evaluates to `true` if the
|
| 218 |
concept’s normalized *constraint-expression* [[temp.constr.decl]] is
|
| 219 |
satisfied [[temp.constr.constr]] by the specified template arguments and
|
| 220 |
`false` otherwise.
|
| 221 |
|
| 222 |
+
[*Note 5*: Since a *constraint-expression* is an unevaluated operand, a
|
| 223 |
concept-id appearing in a *constraint-expression* is not evaluated
|
| 224 |
except as necessary to determine whether the normalized constraints are
|
| 225 |
satisfied. — *end note*]
|
| 226 |
|
| 227 |
[*Example 6*:
|