tmp/tmp0jonem2o/{from.md → to.md}
RENAMED
|
@@ -1,29 +1,33 @@
|
|
| 1 |
### Alias templates <a id="temp.alias">[[temp.alias]]</a>
|
| 2 |
|
| 3 |
A *template-declaration* in which the *declaration* is an
|
| 4 |
*alias-declaration* (Clause [[dcl.dcl]]) declares the *identifier* to
|
| 5 |
-
be
|
| 6 |
types. The name of the alias template is a *template-name*.
|
| 7 |
|
| 8 |
When a *template-id* refers to the specialization of an alias template,
|
| 9 |
it is equivalent to the associated type obtained by substitution of its
|
| 10 |
*template-argument*s for the *template-parameter*s in the *type-id* of
|
| 11 |
-
the alias template.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
``` cpp
|
| 14 |
-
template<class T> struct Alloc {
|
| 15 |
template<class T> using Vec = vector<T, Alloc<T>>;
|
| 16 |
Vec<int> v; // same as vector<int, Alloc<int>{> v;}
|
| 17 |
|
| 18 |
template<class T>
|
| 19 |
void process(Vec<T>& v)
|
| 20 |
-
{
|
| 21 |
|
| 22 |
template<class T>
|
| 23 |
void process(vector<T, Alloc<T>>& w)
|
| 24 |
-
{
|
| 25 |
|
| 26 |
template<template<class> class TT>
|
| 27 |
void f(TT<int>);
|
| 28 |
|
| 29 |
f(v); // error: Vec not deduced
|
|
@@ -31,19 +35,38 @@ f(v); // error: Vec not deduced
|
|
| 31 |
template<template<class,class> class TT>
|
| 32 |
void g(TT<int, Alloc<int>>);
|
| 33 |
g(v); // OK: TT = vector
|
| 34 |
```
|
| 35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
The *type-id* in an alias template declaration shall not refer to the
|
| 37 |
alias template being declared. The type produced by an alias template
|
| 38 |
specialization shall not directly or indirectly make use of that
|
| 39 |
specialization.
|
| 40 |
|
|
|
|
|
|
|
| 41 |
``` cpp
|
| 42 |
template <class T> struct A;
|
| 43 |
template <class T> using B = typename A<T>::U;
|
| 44 |
template <class T> struct A {
|
| 45 |
typedef B<T> U;
|
| 46 |
};
|
| 47 |
B<short> b; // error: instantiation of B<short> uses own type via A<short>::U
|
| 48 |
```
|
| 49 |
|
|
|
|
|
|
|
|
|
| 1 |
### Alias templates <a id="temp.alias">[[temp.alias]]</a>
|
| 2 |
|
| 3 |
A *template-declaration* in which the *declaration* is an
|
| 4 |
*alias-declaration* (Clause [[dcl.dcl]]) declares the *identifier* to
|
| 5 |
+
be an *alias template*. An alias template is a name for a family of
|
| 6 |
types. The name of the alias template is a *template-name*.
|
| 7 |
|
| 8 |
When a *template-id* refers to the specialization of an alias template,
|
| 9 |
it is equivalent to the associated type obtained by substitution of its
|
| 10 |
*template-argument*s for the *template-parameter*s in the *type-id* of
|
| 11 |
+
the alias template.
|
| 12 |
+
|
| 13 |
+
[*Note 1*: An alias template name is never deduced. — *end note*]
|
| 14 |
+
|
| 15 |
+
[*Example 1*:
|
| 16 |
|
| 17 |
``` cpp
|
| 18 |
+
template<class T> struct Alloc { ... };
|
| 19 |
template<class T> using Vec = vector<T, Alloc<T>>;
|
| 20 |
Vec<int> v; // same as vector<int, Alloc<int>{> v;}
|
| 21 |
|
| 22 |
template<class T>
|
| 23 |
void process(Vec<T>& v)
|
| 24 |
+
{ ... }
|
| 25 |
|
| 26 |
template<class T>
|
| 27 |
void process(vector<T, Alloc<T>>& w)
|
| 28 |
+
{ ... } // error: redefinition
|
| 29 |
|
| 30 |
template<template<class> class TT>
|
| 31 |
void f(TT<int>);
|
| 32 |
|
| 33 |
f(v); // error: Vec not deduced
|
|
|
|
| 35 |
template<template<class,class> class TT>
|
| 36 |
void g(TT<int, Alloc<int>>);
|
| 37 |
g(v); // OK: TT = vector
|
| 38 |
```
|
| 39 |
|
| 40 |
+
— *end example*]
|
| 41 |
+
|
| 42 |
+
However, if the *template-id* is dependent, subsequent template argument
|
| 43 |
+
substitution still applies to the *template-id*.
|
| 44 |
+
|
| 45 |
+
[*Example 2*:
|
| 46 |
+
|
| 47 |
+
``` cpp
|
| 48 |
+
template<typename...> using void_t = void;
|
| 49 |
+
template<typename T> void_t<typename T::foo> f();
|
| 50 |
+
f<int>(); // error, int does not have a nested type foo
|
| 51 |
+
```
|
| 52 |
+
|
| 53 |
+
— *end example*]
|
| 54 |
+
|
| 55 |
The *type-id* in an alias template declaration shall not refer to the
|
| 56 |
alias template being declared. The type produced by an alias template
|
| 57 |
specialization shall not directly or indirectly make use of that
|
| 58 |
specialization.
|
| 59 |
|
| 60 |
+
[*Example 3*:
|
| 61 |
+
|
| 62 |
``` cpp
|
| 63 |
template <class T> struct A;
|
| 64 |
template <class T> using B = typename A<T>::U;
|
| 65 |
template <class T> struct A {
|
| 66 |
typedef B<T> U;
|
| 67 |
};
|
| 68 |
B<short> b; // error: instantiation of B<short> uses own type via A<short>::U
|
| 69 |
```
|
| 70 |
|
| 71 |
+
— *end example*]
|
| 72 |
+
|