表示函数参数的元组的类型表达式

Type expression for a tuple representing arguments to a function

我正在寻找一种方法来为表示函数所需参数的 std::tuple 创建类型表达式。考虑以下因素:

template<typename F, typename ...args>
void myfunction(F&& function, A... args)
{
    std::tuple</*???*/> arguments;
    populate_tuple(arguments,args...);
    return apply(function,arguments);
}

... 其中 F 是普通函数类型,apply() 是将参数应用于函数的函数,而 populate_tuple() 在之前对参数做一些工作(包括类型转换)用函数调用的最终参数填充元组。

注意:我不能在元组的声明中使用args...,因为这些是不是的类型该函数期望 - populate_tuple() 进行转换。

我感觉好像编译器拥有执行此操作所需的一切,但我不知道该语言是否支持它。有任何想法吗?所有帮助表示赞赏。

大概是这样的:

template <typename T> struct TupleOfArguments;

template <typename R, typename ... Args>
struct TupleOfArguments<R(Args...)> {
  typedef std::tuple<Args...> type;
};

Demo

这个有用吗?

template<typename F, typename ...Args>
void myfunction(F&& function, Args&&... args) {
     return apply(std::forward<F>(function), std::make_tuple(std::forward<Args>(args)...));
}