类中的多个包展开具有固定数量的模板参数
Multiple pack expansions inside class with fixed number of template arguments
代码格式正确吗?函数模板本身的声明在clang和gcc中都给出了错误,即使Ts
很可能是空的。
// error: too many template arguments for class template 'pair'
template<class I, class U, class... Ts>
void f(std::pair<I,U,Ts...>);
int main()
{
f(std::pair<int,int>());
}
函数调用在gcc中给出了这个没有意义的错误。没有转换到int
:
note: cannot convert 'std::pair<int, int>()' (type 'std::pair<int, int>') to type 'int'
[temp.res]/8:
如果可变模板的每个有效特化都需要一个空的模板参数包,模板格式错误,无诊断必需的。
f
的每个有效专门化都要求Ts
是一个空包。因此,该程序是病态的NDR。两个编译器都是正确的
对于GCC的诊断,这似乎是由于它习惯使用int
作为占位符,用于"看起来像类型但没有意义的东西",以用于错误恢复。
相关文章:
- 切换到 Visual Studio 2019 后,必须在此上下文中展开参数包
- 为什么可变参数模板参数包未展开
- 如何从右到左展开参数包
- 存储未展开的参数包
- 声明类型包含未展开的参数包'Args'
- 使用声明包含未展开的参数包
- 表达式包含未展开的参数包
- 在其静态递归函数中展开结构类型模板参数包
- 是否允许类模板的函数签名模板参数中使用未展开的参数包?(可能的VS2013错误)
- 同一表达式中多个参数包的多次展开
- 如何展开基类的参数包并调用每个基类的成员函数
- 展开具有不同长度的参数包
- 类中的多个包展开具有固定数量的模板参数
- 在处理函数的部分模板专门化时,类型定义和参数包展开问题
- 我可以展开一个参数包并定义一个参数列表吗?
- 使用对齐符展开参数包的语法是什么?
- 参数包列表展开导致可变构造函数重载失败
- 可变参数函数:表达式包含未展开的参数包'args'
- 括号内的参数包展开会产生奇怪的输出
- 使用参数包展开调用带有可变参数的函数,但修改第i个参数