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

Tre*_*key 8 c++ templates typedef template-aliases c++14

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

#include <vector>

int main(){

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

    //type instantiation:
    type<int> t;

}
Run Code Online (Sandbox Code Playgroud)

错误:模板声明不能出现在块范围内

为什么我们被迫将这些声明置于块范围之外?

#include <vector>

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

int main(){

    //type instantiation:
    type<int> t;
}
Run Code Online (Sandbox Code Playgroud)

R S*_*ahu 5

该标准是这样说的。

从C ++ 11标准(重点是我的):

14模板

2模板声明只能作为名称空间范围或类范围声明出现。在功能模板声明中,declarator-id的最后一个组成部分不得为template-id。[注意:最后一个组件可以是标识符,运算符功能ID,转换功能ID或文字运算符ID。在类模板声明中,如果类名称是simple-template-id,则声明将声明类模板局部特化(14.5.5)。—尾注]