Files
cppdraft_translate/cppdraft/temp/alias.md
2025-10-25 03:02:53 +03:00

4.8 KiB
Raw Blame History

[temp.alias]

13 Templates [temp]

13.7 Template declarations [temp.decls]

13.7.8 Alias templates [temp.alias]

1

#

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.

2

#

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]

3

#

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]

4

#

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]

5

#

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]