模板别名上下文中的模板<>模板<>语法有什么用?

What is template<> template<> syntax in the context of template-alias for?

本文关键字:gt lt 什么 语法 模板 上下文 别名      更新时间:2023-10-16

(这个问题与模板模板参数无关。)

我刚刚发现GCC编译这样的代码

template <typename A, typename B>
struct P {};
template <typename A>
template <typename B>
using Q = P<A, B>;

其中CCD_ 1是双重模板化的名称。

但我不能用这个。当我写Q<short><long>时,我得到

template_template.cpp:10:5: error: ‘Q<short int>’ is not a template
Q<short><long>{};
^~~~~~~~
template_template.cpp:10:20: error: invalid use of incomplete type ‘Q<short int>’
Q<short><long>{};
^
template_template.cpp:2:8: note: declaration of ‘Q<short int>’
struct P {};

为什么要编译第一个代码段?

是否有语法可以让编译器相信Q<short>实际上是一个模板?

//GCC 6.3.0

C++14标准在14p1:中说明

模板声明中的声明
--声明或定义函数、类或变量,或
-定义类模板或嵌套在类模板内的类的成员函数、成员类、成员枚举或静态数据成员,或
--是别名声明

此处,模板声明中的声明版声明,其本身包含

别名声明语法的相关部分是:

模板声明
 nbsp nbsp;模板<模板参数列表>声明

别名声明


 nbsp nbsp;使用标识符属性说明符seqopt=类型id

其中声明可以是模板声明

别名声明请注意,语法本身接受给定的代码,但上面文本中的附加限制使其无效。