Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/126.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++_Templates - Fatal编程技术网

C++在模板中使用元组作为参数包

C++在模板中使用元组作为参数包,c++,templates,C++,Templates,我使用boost::callable\u traits::args\u t从方法中获取参数类型的std::tuple。是否可以将该元组用作参数包 void doJob(int i) { std::cout << i << std::endl; } template<auto F> void magic(boost::callable_traits::args_t<F> ...args) { // here is the magic F(ar

我使用boost::callable\u traits::args\u t从方法中获取参数类型的std::tuple。是否可以将该元组用作参数包

void doJob(int i) {
  std::cout << i << std::endl;
}
template<auto F>
void magic(boost::callable_traits::args_t<F> ...args) { // here is the magic
  F(args...)
}
magic<doJob>(1);

这是我想要实现的。我想在不使用可变模板的情况下实现这一点。

如果可以使用C++17,则可以使用来调用函数。apply接受一个可调用的和一个元组,并使用未打包的元组作为函数参数调用可调用的。那会让魔术看起来像

template<auto F>
void magic(boost::callable_traits::args_t<F> args) { // here is the magic
  std::apply(F, args);
}

如果没有可变模板,则无法进行参数包扩展。为什么不要求使用一个呢?你想要一个看起来和行为都像可变模板包的东西,但不需要使用一个???@user10605163,fixed@super,确切地说,没有可变模板是不可能做你想做的事情的,但是有了可变模板,你就可以做到,所以magic1;按原样工作。这不是我想要的。所以我想这样做-模板void magicARGS…args但没有变量模板。@crashtua我明白了。如果没有可变模板参数,则无法获得参数包。