Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why there is no templated typedef in C++11? [duplicate]

Why the Committee decided not to approve templated typedef along with templated using?

template <class T>
using my_vector = std::vector<T>;

is legal.

But

template <class T>
typedef std::vector<T> my_vector<T>;

is illegal?

Upd. The question Why does C++11 not have template typedef? is NOT answering.

like image 291
vladon Avatar asked Dec 24 '22 20:12

vladon


1 Answers

Quoting from the proposal Templates aliases for C++ N1489 (Emphasis Mine):

It has been suggested to (re)use the keyword typedef — as done in the paper [4] — to introduce template aliases:

template<class T>
typedef std::vector<T, MyAllocator<T> > Vec;

That notation has the advantage of using a keyword already known to introduce a type alias. However, it also displays several disavantages among which the confusion of using a keyword known to introduce an alias for a type-name in a context where the alias does not designate a type, but a template; Vec is not an alias for a type, and should not be taken for a typedef-name. The name Vec is a name for the family std::vector<., MyAllocator<.>> – where the bullet is a placeholder for a type-name. Consequently we do not propose the “typedef” syntax.

[4] Herb Sutter, Typedef templates, document no. WG21/1406.

like image 54
101010 Avatar answered Jan 08 '23 03:01

101010