Почему
template<class T> using Vec = vector<T, Alloc<T>>;
а не
template<class T> typedef vector<T, Alloc<T>> Vec;
?
Здравствуйте, 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 typedefas 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.
Здравствуйте, _NN_, Вы писали:
_NN>http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2003/n1489.pdf
Ого, ещё в 2003 придумали. 9 лет пилили новый стандарт, а тут за 3 года раскачались уже и до реализации фич стандарта 2017.