Since now (C++14) we have capture by move, is there any reason why the code below should not compile?
template<typename F, typename... T>
auto apply(F&& f, T&&...t)
{
return [p = std::forward<F>(f), q... = std::forward<T>(t)...](){ p(q...); };
}
template<typename F, typename... T>
auto apply(F&& f, T&&...t)
{
return [p = std::forward<F>(f), t...](){ p(t...); };
}
template<typename F, typename... T>
auto apply(F&& f, T&&...t)
{
return [p = std::forward<F>(f), q... = std::forward<T>(t)...](){ p(q...); };
}
template<typename F, typename... T>
auto apply(F&& f, T&&...t)
{
return [f = std::forward<F>(f),
t = std::forward_as_tuple<T...>(std::forward<T>(t)...)
]() mutable { return std::apply(std::forward<F>(f), t); };
}
Yes, a pack expansion can't generate variables, whether in a declaration-initialization or in an init-capture.
There's a conceptual difference; with a simple-capture it's the same identifier within the lambda body as outside, just with a different referent, while an init-capture introduces a new identifier possibly shadowing one in the enclosing scope. Currently templates (function, class, alias) are the only syntactic constructs that can introduce variadic identifiers. A proposal would definitely be worthwhile.
Some issues you might consider:
What is allowed on the rhs of a variadic init-capture; if it has to be a pack expansion, are other comma sequences allowed?
Alternatively, would it be better to omit the ellipsis on the lhs and use an unexpanded pack on the rhs?
On 3 Oct 2014 14:26, "Edward Catmur" <eca...@googlemail.com> wrote:
> What is allowed on the rhs of a variadic init-capture; if it has to be a pack expansion, are other comma sequences allowed?
That should have been: does it have to be a pack expansion, or are other comma sequences allowed?