vla*_*don 4 c++ templates typedef using c++11
为什么委员会决定不与模板typedef一起批准using?
template <class T>
using my_vector = std::vector<T>;
Run Code Online (Sandbox Code Playgroud)
是合法的.
但
template <class T>
typedef std::vector<T> my_vector<T>;
Run Code Online (Sandbox Code Playgroud)
是非法的?
UPD.问题为什么C++ 11没有模板typedef?没有回答.
101*_*010 10
引用C++ N1489(Emphasis Mine)的提议模板别名:
有人建议(重新)使用关键字
typedef- 如论文[4]中所做的那样 - 来引入模板别名:Run Code Online (Sandbox Code Playgroud)template<class T> typedef std::vector<T, MyAllocator<T> > Vec;该符号具有使用已知的关键字引入类型别名的优点.然而,它还显示了一些不利之处,其中混淆使用已知的关键字在别名未指定类型但模板的上下文中为类型名称引入别名;
Vec不是类型的别名,不应该用于typedef-name.该名称Vec是该系列的名称std::vector<., MyAllocator<.>>- 其中项目符号是类型名称的占位符.因此,我们不提出"typedef"语法.[4] Herb Sutter,Typedef模板,文件号.WG21/1406.