简体   繁体   中英

Is it possible to unfold a variadic (lambda) template and the pass those functions return value to another variadic function?

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 convert double .

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.)

Syntax would be:

template <typename... Fs>
auto parse(int x, Fs... func)
{
    return test(funcs(x)...);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM