C++ 为什么可以';我不能在函数中声明模板化的类型别名吗?

C++ 为什么可以';我不能在函数中声明模板化的类型别名吗?,c++,templates,typedef,c++14,template-aliases,C++,Templates,Typedef,C++14,Template Aliases,为什么我不能在函数中声明模板类型别名 #include <vector> int main(){ //type alias deceleration: template <typename T> using type = std::vector<T>; //type instantiation: type<int> t; } #包括 int main(){ //类型别名减速: 模板 使用type=s

为什么我不能在函数中声明模板类型别名

#include <vector>

int main(){

    //type alias deceleration:
    template <typename T>
    using type = std::vector<T>;

    //type instantiation:
    type<int> t;

}
#包括
int main(){
//类型别名减速:
模板
使用type=std::vector;
//类型实例化:
t型;
}
错误:模板声明不能出现在块范围中

为什么我们不得不将这些声明放在块范围之外

#include <vector>

//type alias deceleration:
template <typename T>
using type = std::vector<T>;

int main(){

    //type instantiation:
    type<int> t;
}
#包括
//类型别名减速:
模板
使用type=std::vector;
int main(){
//类型实例化:
t型;
}
标准上是这么说的

来自C++11标准(重点):

14模板

2模板声明只能作为命名空间范围或类范围声明出现。在函数模板声明中,声明器id的最后一个组件不应是模板id。[注意:最后一个组件可能是标识符、运算符函数id、转换函数id或literal-operator-id。在类模板声明中,如果类名是简单模板id,则声明声明类模板部分专用化(14.5.5)。-结束注]


您可以在函数内部声明类型别名。这里有一个模板别名。@user207933对。调整了问题。根据当前的答案,“标准是这样说的”,您能否澄清问题是否是“为什么决定不允许这样做?”,这是我最初的阅读方式。请参阅和。“EWG未能为这次扩展找到足够的动机”。所以,因为他们“未能找到足够的动机”来允许它。