tmp/tmpp2yzjds_/{from.md → to.md}
RENAMED
|
@@ -31,13 +31,13 @@ template-argument:
|
|
| 31 |
constant-expression
|
| 32 |
type-id
|
| 33 |
id-expression
|
| 34 |
```
|
| 35 |
|
| 36 |
-
The name lookup rules ([[basic.lookup]]) are used to
|
| 37 |
-
of a name with a template declaration; that is, to
|
| 38 |
-
*template-name*.
|
| 39 |
|
| 40 |
For a *template-name* to be explicitly qualified by the template
|
| 41 |
arguments, the name must be known to refer to a template.
|
| 42 |
|
| 43 |
After name lookup ([[basic.lookup]]) finds that a name is a
|
|
@@ -47,34 +47,49 @@ of which is a function template, if this is followed by a `<`, the `<`
|
|
| 47 |
is always taken as the delimiter of a *template-argument-list* and never
|
| 48 |
as the less-than operator. When parsing a *template-argument-list*, the
|
| 49 |
first non-nested `>`[^2] is taken as the ending delimiter rather than a
|
| 50 |
greater-than operator. Similarly, the first non-nested `>{>}` is treated
|
| 51 |
as two consecutive but distinct `>` tokens, the first of which is taken
|
| 52 |
-
as the end of the and completes the
|
| 53 |
-
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
``` cpp
|
| 57 |
-
template<int i> class X {
|
| 58 |
|
| 59 |
X< 1>2 > x1; // syntax error
|
| 60 |
X<(1>2)> x2; // OK
|
| 61 |
|
| 62 |
-
template<class T> class Y {
|
| 63 |
Y<X<1>> x3; // OK, same as Y<X<1> > x3;
|
| 64 |
Y<X<6>>1>> x4; // syntax error
|
| 65 |
Y<X<(6>>1)>> x5; // OK
|
| 66 |
```
|
| 67 |
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
|
| 77 |
``` cpp
|
| 78 |
struct X {
|
| 79 |
template<std::size_t> X* alloc();
|
| 80 |
template<std::size_t> static X* adjust();
|
|
@@ -85,18 +100,25 @@ template<class T> void f(T* p) {
|
|
| 85 |
T::adjust<100>(); // ill-formed: < means less than
|
| 86 |
T::template adjust<100>(); // OK: < starts template argument list
|
| 87 |
}
|
| 88 |
```
|
| 89 |
|
|
|
|
|
|
|
| 90 |
A name prefixed by the keyword `template` shall be a *template-id* or
|
| 91 |
-
the name shall refer to a class template
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
in
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
|
| 99 |
``` cpp
|
| 100 |
template <class T> struct A {
|
| 101 |
void f(int);
|
| 102 |
template <class U> void f(U);
|
|
@@ -115,10 +137,12 @@ template <class T> struct B {
|
|
| 115 |
// OK: T::template C names a class template:
|
| 116 |
template <class T, template <class X> class TT = T::template C> struct D { };
|
| 117 |
D<B<int> > db;
|
| 118 |
```
|
| 119 |
|
|
|
|
|
|
|
| 120 |
A *simple-template-id* that names a class template specialization is a
|
| 121 |
*class-name* (Clause [[class]]).
|
| 122 |
|
| 123 |
A *template-id* that names an alias template specialization is a
|
| 124 |
*type-name*.
|
|
|
|
| 31 |
constant-expression
|
| 32 |
type-id
|
| 33 |
id-expression
|
| 34 |
```
|
| 35 |
|
| 36 |
+
[*Note 1*: The name lookup rules ([[basic.lookup]]) are used to
|
| 37 |
+
associate the use of a name with a template declaration; that is, to
|
| 38 |
+
identify a name as a *template-name*. — *end note*]
|
| 39 |
|
| 40 |
For a *template-name* to be explicitly qualified by the template
|
| 41 |
arguments, the name must be known to refer to a template.
|
| 42 |
|
| 43 |
After name lookup ([[basic.lookup]]) finds that a name is a
|
|
|
|
| 47 |
is always taken as the delimiter of a *template-argument-list* and never
|
| 48 |
as the less-than operator. When parsing a *template-argument-list*, the
|
| 49 |
first non-nested `>`[^2] is taken as the ending delimiter rather than a
|
| 50 |
greater-than operator. Similarly, the first non-nested `>{>}` is treated
|
| 51 |
as two consecutive but distinct `>` tokens, the first of which is taken
|
| 52 |
+
as the end of the *template-argument-list* and completes the
|
| 53 |
+
*template-id*.
|
| 54 |
+
|
| 55 |
+
[*Note 2*: The second `>` token produced by this replacement rule may
|
| 56 |
+
terminate an enclosing *template-id* construct or it may be part of a
|
| 57 |
+
different construct (e.g. a cast). — *end note*]
|
| 58 |
+
|
| 59 |
+
[*Example 1*:
|
| 60 |
|
| 61 |
``` cpp
|
| 62 |
+
template<int i> class X { ... };
|
| 63 |
|
| 64 |
X< 1>2 > x1; // syntax error
|
| 65 |
X<(1>2)> x2; // OK
|
| 66 |
|
| 67 |
+
template<class T> class Y { ... };
|
| 68 |
Y<X<1>> x3; // OK, same as Y<X<1> > x3;
|
| 69 |
Y<X<6>>1>> x4; // syntax error
|
| 70 |
Y<X<(6>>1)>> x5; // OK
|
| 71 |
```
|
| 72 |
|
| 73 |
+
— *end example*]
|
| 74 |
+
|
| 75 |
+
The keyword `template` is said to appear at the top level in a
|
| 76 |
+
*qualified-id* if it appears outside of a *template-argument-list* or
|
| 77 |
+
*decltype-specifier*. In a *qualified-id* of a *declarator-id* or in a
|
| 78 |
+
*qualified-id* formed by a *class-head-name* (Clause [[class]]) or
|
| 79 |
+
*enum-head-name* ([[dcl.enum]]), the keyword `template` shall not
|
| 80 |
+
appear at the top level. In a *qualified-id* used as the name in a
|
| 81 |
+
*typename-specifier* ([[temp.res]]), *elaborated-type-specifier* (
|
| 82 |
+
[[dcl.type.elab]]), *using-declaration* ([[namespace.udecl]]), or
|
| 83 |
+
*class-or-decltype* (Clause [[class.derived]]), an optional keyword
|
| 84 |
+
`template` appearing at the top level is ignored. In these contexts, a
|
| 85 |
+
`<` token is always assumed to introduce a *template-argument-list*. In
|
| 86 |
+
all other contexts, when naming a template specialization of a member of
|
| 87 |
+
an unknown specialization ([[temp.dep.type]]), the member template name
|
| 88 |
+
shall be prefixed by the keyword `template`.
|
| 89 |
+
|
| 90 |
+
[*Example 2*:
|
| 91 |
|
| 92 |
``` cpp
|
| 93 |
struct X {
|
| 94 |
template<std::size_t> X* alloc();
|
| 95 |
template<std::size_t> static X* adjust();
|
|
|
|
| 100 |
T::adjust<100>(); // ill-formed: < means less than
|
| 101 |
T::template adjust<100>(); // OK: < starts template argument list
|
| 102 |
}
|
| 103 |
```
|
| 104 |
|
| 105 |
+
— *end example*]
|
| 106 |
+
|
| 107 |
A name prefixed by the keyword `template` shall be a *template-id* or
|
| 108 |
+
the name shall refer to a class template or an alias template.
|
| 109 |
+
|
| 110 |
+
[*Note 3*: The keyword `template` may not 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 in cases where it is not strictly necessary; i.e.,
|
| 115 |
+
when the *nested-name-specifier* or the expression on the left of the
|
| 116 |
+
`->` or `.` is not dependent on a *template-parameter*, or the use does
|
| 117 |
+
not appear in the scope of a template. — *end note*]
|
| 118 |
+
|
| 119 |
+
[*Example 3*:
|
| 120 |
|
| 121 |
``` cpp
|
| 122 |
template <class T> struct A {
|
| 123 |
void f(int);
|
| 124 |
template <class U> void f(U);
|
|
|
|
| 137 |
// OK: T::template C names a class template:
|
| 138 |
template <class T, template <class X> class TT = T::template C> struct D { };
|
| 139 |
D<B<int> > db;
|
| 140 |
```
|
| 141 |
|
| 142 |
+
— *end example*]
|
| 143 |
+
|
| 144 |
A *simple-template-id* that names a class template specialization is a
|
| 145 |
*class-name* (Clause [[class]]).
|
| 146 |
|
| 147 |
A *template-id* that names an alias template specialization is a
|
| 148 |
*type-name*.
|