标准是否完美定义了以下内容?
#include <iostream>
template <unsigned int... Values, class... Types>
void f(Types&&... values)
{
std::cout<<sizeof...(Values)<<" "<<sizeof...(Types)<<std::endl;
}
int main()
{
f<7, 5>(3);
return 0;
}
在g++ 4.8
下编译很好,不知道是否正常。
最佳答案
来自 ISO C++ standard's current working draft 14.1(11):
A template parameter pack of a function template shall not be followed by another template >parameter unless that template parameter can be deduced from the parameter-type-list of >the function template or has a default argument
在您的情况下,“类型”是一个 函数参数包,而“值”是一个 模板参数包,后面总是可以跟一个 函数参数包。 这段代码也出于同样的原因工作:
#include <iostream>
template <class... Values, class... Types>
void f(Types&&... values)
{
std::cout<<sizeof...(Values)<<" "<<sizeof...(Types)<<std::endl;
}
int main()
{
f<int, float>(-3, 5);
return 0;
}
关于c++ - 混合可变参数模板值和可变参数推导类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21101391/