Почему для template alias взяли using, а не typedef?
От: enji  
Дата: 26.07.15 14:05
Оценка:
Почему
template<class T> using Vec = vector<T, Alloc<T>>;


а не
template<class T> typedef vector<T, Alloc<T>> Vec;

?
Re: Почему для template alias взяли using, а не typedef?
От: BulatZiganshin  
Дата: 26.07.15 18:54
Оценка: +1
Здравствуйте, enji, Вы писали:

1. для того чтобы избавиться от мозговыносящего синтаксиса: typedef int (*f)();
2. using может определять параметризованные типы, не уверен что в typedef это бы вписалось
Люди, я люблю вас! Будьте бдительны!!!
Re: Почему для template alias взяли using, а не typedef?
От: _NN_ www.nemerleweb.com
Дата: 26.07.15 18:55
Оценка: 38 (2)
Здравствуйте, enji, Вы писали:

В кратце для семейства типов:
template<typename T> using Vec<T> = std::vector<T, MyAllocator<T>>;



http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2003/n1489.pdf

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 disadvantages 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.

On the other hand the sentence
template<class T>
using Vec = std::vector<T, MyAllocator<T> >;
can be read/interpreted as: from now on, I'll be using Vec<T> as a synonym
for std::vector<T, MyAllocator<T> >. With that reading, the new
syntax for aliasing seems reasonably logical. Therefore, we propose the
following formal syntax for the declaration of a parameterized type alias:
template < template-parameter-list > alias-declaration
alias-declaration:
using identier = type-id
A key question is: does it t with/generalize existing name aliasing
mechanism? That topic will be discussed in  2.

http://rsdn.nemerleweb.com
http://nemerleweb.com
Re[2]: Почему для template alias взяли using, а не typedef?
От: flаt  
Дата: 27.07.15 03:51
Оценка: :)
Здравствуйте, _NN_, Вы писали:

_NN>http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2003/n1489.pdf

Ого, ещё в 2003 придумали. 9 лет пилили новый стандарт, а тут за 3 года раскачались уже и до реализации фич стандарта 2017.
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.