Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/161.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 具有特定模板类型的可变参数数的模板函数 模板 结构向量{};_C++_Variadic Templates - Fatal编程技术网

C++ 具有特定模板类型的可变参数数的模板函数 模板 结构向量{};

C++ 具有特定模板类型的可变参数数的模板函数 模板 结构向量{};,c++,variadic-templates,C++,Variadic Templates,现在我想写一个函数,它只接受这些向量,但模板参数的值不同。可以这样称呼: template <int S> struct Vec {}; f(Vec(),Vec(),Vec()); 如何编写这样的函数?我想使用参数包。可能是这样的: f(Vec<1>(), Vec<2>(), Vec<3>()); 模板 f(Vec-vecs); 我想让用户看到,函数只需要从其声明中获得向量,而不是从编译错误中获得向量。您需要使用: template<

现在我想写一个函数,它只接受这些向量,但模板参数的值不同。可以这样称呼:

template <int S>
struct Vec {};
f(Vec(),Vec(),Vec());
如何编写这样的函数?我想使用参数包。可能是这样的:

f(Vec<1>(), Vec<2>(), Vec<3>());
模板
f(Vec-vecs);
我想让用户看到,函数只需要从其声明中获得向量,而不是从编译错误中获得向量。

您需要使用:

template<int... Ss>
f(Vec<Ss...> vecs);
模板
void f(Vec…vecs){…}
在我的设置中生成的程序:

template <int... Ss>
void f(Vec<Ss>... vecs) { ... }
模板
结构向量{};
模板
无效f(向量…向量)
{
}
int main()
{
f(Vec(),Vec(),Vec());
}
template <int S>
struct Vec {};

template <int... Ss>
void f(Vec<Ss>... vecs)
{
}

int main()
{
   f(Vec<1>(), Vec<2>(), Vec<3>());
}