具有某些模板类型的参数数量可变的模板函数
Templated function with variable number of params of certain templated type
template <int S>
struct Vec {};
现在,我想编写一个仅接受这些向量但具有不同模板参数值的函数。可以这样称呼:
f(Vec<1>(), Vec<2>(), Vec<3>());
如何编写这样的功能?我想使用参数包。可能是:
template<int... Ss>
f(Vec<Ss...> vecs);
我想让用户看到该函数的期望是从其声明而不是从编译错误中获得的。
您需要使用:
template <int... Ss>
void f(Vec<Ss>... vecs) { ... }
在我的设置中构建的程序:
template <int S>
struct Vec {};
template <int... Ss>
void f(Vec<Ss>... vecs)
{
}
int main()
{
f(Vec<1>(), Vec<2>(), Vec<3>());
}
相关文章:
- 如何使用指针传递给函数的数组中对象的函数成员
- 从 C++ 中的函数返回数组地址问题
- 有没有办法使用递归函数找到数组中最小值的 INDEX?C++
- C++从函数指针数组调用函数
- 将返回值存储在函数指针数组的指针中是如何工作的?
- 将函数指针数组中的函数指针作为模板参数传递
- 具有推导参数的模板函数指针数组变量
- 是否可以遍历传递给函数的数组?
- 是否可以使用函数指针数组来删除分支
- 如何从 c++ 中的函数返回数组
- 如何按 C++ 中的值从函数返回数组
- 如何调用函数指针数组中的函数?
- 尝试通过多个函数移动数组,但遇到了我不知道如何修复的错误
- 如何使函数返回数组?用于制作在VB.NET中使用的DLL
- 有没有一种方法可以获得传递给函数的数组的大小
- 如何使用递归函数返回数组中整数的索引?
- 从函数返回数组时是否需要删除
- 为什么从函数返回数组时需要将数组声明为静态数组.(C++)
- 调用函数后数组中的垃圾
- C++:易失性实例中的易失性成员函数 - 将数组分配给指针是无效的转换?