Reputation: 430
So I wonder given a variadic template function like following:
template<typename...Fs>
parse(int x, Fs...funcs);
Where we ensure (through C++20 concept) that is convertible to std::function<double(int)>
. Could we use unfold it into another functions argument, like passing to following one:
template<typename...Ts>
test(Ts...args);
Where again we ensure all Ts
is and must be able to convertdouble
.
What is expecting is, suppose a
, b
, c
are lambda expressions, calling parse(12, a, b, c)
is equivalent to calling test(a(12), b(12), c(12))
.
Something I tried is like following
template<typename...Fs>
parse(int x, Fs...func) {
return test(..., funcs(x));
}
But didn't work. It seems like that most unfolding expression examples puts a function within the expression, so does this means unfold expression by itself can't return as a list of arguments. Instead, perhaps it could only return as single value?
If so, is there any workaround like first construct it into an array like (..., void(arr[i++]=args))
, but I couldn't find ways to expand it back to argument pack. (I would want to expand arguments back to argument pack as I want to reuse other functions within my library instead of writing another one that takes either array or initializer list as argument.)
Upvotes: 0
Views: 370
Reputation: 217065
Syntax would be:
template <typename... Fs>
auto parse(int x, Fs... func)
{
return test(funcs(x)...);
}
Upvotes: 1