C++ c++;如何使用Variadic创建闭包?

C++ c++;如何使用Variadic创建闭包?,c++,closures,std-function,variadic,pybind11,C++,Closures,Std Function,Variadic,Pybind11,我试图将这个Python代码重写为它的等价pyBixC++。 但是我不能让我的C++代码接受未知量的参数 python: def primitive(f_raw): def f_wrapped(*args, **kwargs): return f_raw(*args, **kwargs) return f_wrapped c++: 模板 std::function primative(std::function callable) { 返回[=](T…参

我试图将这个Python代码重写为它的等价pyBixC++。 但是我不能让我的C++代码接受未知量的参数

python:

def primitive(f_raw):
    def f_wrapped(*args, **kwargs):
            return f_raw(*args, **kwargs)
    return f_wrapped
c++:

模板
std::function primative(std::function callable)
{
返回[=](T…参数){
返回可调用(参数…);
};
}

您必须在此处使用两个模板参数

template <class T, class... Ts>
std::function<T(Ts...)> primative(std::function<T(Ts...)> callable)
{
  return [=](Ts... params){
    return callable(params...);
  };
}
模板
std::function primative(std::function callable)
{
返回[=](Ts…params){
返回可调用(参数…);
};
}

Ts..
是一个,它可以包含任何类型。

使用函数
const auto bound=primative(xtadd)的正确方法是什么;束缚(1,2)链接提供了所有的使用方法。这应该实现什么?至少对于C++情况,返回的回调将与您通过的内容相同,只是它将按值传递所有内容。
template <class T, class... Ts>
std::function<T(Ts...)> primative(std::function<T(Ts...)> callable)
{
  return [=](Ts... params){
    return callable(params...);
  };
}