具有固定数量的模板参数的类内的多包扩展

时间:2015-10-03 01:25:58

标签: c++ templates c++11

这段代码是否格式正确?函数模板本身的声明在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'

1 个答案:

答案 0 :(得分:4)

[temp.res] / 8:

  

如果可变参数模板的每个有效特化都需要为空   模板参数包,模板格式错误,无需诊断   必需的。

f的每个有效专业化都需要Ts为空包。因此,该计划是不正常的NDR。两个编译器都是正确的。

关于海湾合作委员会的诊断,这似乎是由于习惯使用int作为占位符来看待某种类型,但没有意义的#&#34} 34;用于错误恢复目的。