[英]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)>
.我们确保(通过 C++20 概念)可以转换为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
.我们再次确保所有Ts
是并且必须能够转换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))
.期望的是,假设a
, b
, c
是 lambda 表达式,调用parse(12, a, b, c)
等效于调用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.如果是这样,是否有任何解决方法,例如首先将其构造为(..., void(arr[i++]=args))
类的数组,但我找不到将其扩展回参数包的方法。 (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)...);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.