所以我有一些类型X:
typedef ... X;
Run Code Online (Sandbox Code Playgroud)
和模板功能f:
class <typename T>
void f(X& x_out, const T& arg_in);
Run Code Online (Sandbox Code Playgroud)
然后是一个功能g:
void g(const X* x_array, size_t x_array_size);
Run Code Online (Sandbox Code Playgroud)
我需要编写一个variadic模板函数h来执行此操作:
template<typename... Args>
void h(Args... args)
{
constexpr size_t nargs = sizeof...(args); // get number of args
X x_array[nargs]; // create X array of that size
for (int i = 0; i < nargs; i++) // foreach arg
f(x_array[i], args[i]); // call f (doesn't work)
g(x_array, nargs); // call g with …Run Code Online (Sandbox Code Playgroud)