4.8 KiB
[temp.alias]
13 Templates [temp]
13.7 Template declarations [temp.decls]
13.7.8 Alias templates [temp.alias]
A template-declaration in which the declaration is analias-declaration ([dcl.pre]) declares theidentifier to be an alias template.
An alias template is a name for a family of types.
The name of the alias template is a template-name.
A
template-id that is not the operand of a reflect-expression or
splice-specialization-specifier
that designates the specialization of an alias template is equivalent to the associated type obtained by substitution of its template-arguments for thetemplate-parameters in the defining-type-id of the alias template.
Any other template-id that names a specialization of an alias template is a typedef-name for a type alias.
[Note 1:
An alias template name is never deduced.
â end note]
[Example 1: template struct Alloc { /* ... / };template using Vec = vector<T, Alloc>; Vec v; // same as vector<int, Alloc> v;templatevoid process(Vec& v){ / ... / }templatevoid process(vector<T, Alloc>& w){ / ... */ } // error: redefinitiontemplate<template class TT>void f(TT);
f(v); // error: Vec not deducedtemplate<template<class,class> class TT>void g(TT<int, Alloc>); g(v); // OK, TT = vector â end example]
However, if the template-id is dependent, subsequent template argument substitution still applies to the template-id.
[Example 2: template<typename...> using void_t = void;template void_t f(); f(); // error: int does not have a nested type foo â end example]
The defining-type-id in an alias template declaration shall not refer to the alias template being declared.
The type produced by an alias template specialization shall not directly or indirectly make use of that specialization.
[Example 3: template struct A;template using B = typename A::U;template struct A {typedef B U;}; B b; // error: instantiation of B uses own type via A::U â end example]
The type of a lambda-expression appearing in an alias template declaration is different between instantiations of that template, even when the lambda-expression is not dependent.
[Example 4: template using A = decltype([] { }); // A and A refer to different closure types â end example]