A simple-capture followed by an ellipsis is a pack expansion (14.5.3). An init-capture followed by an ellipsis is ill-formed.
I don't quite understand the underlying problem. Currently, when capturing a pack, and the name of the pack is found inside the lambda, it also has to be constructed from some kind of member (or members) inside the lambda object. With init-capture, this would just require a different name to be recognized, no?
On Sunday, July 28, 2013 9:18:23 PM UTC+2, Richard Smith wrote:On Sun, Jul 28, 2013 at 10:40 AM, Xeo <hivem...@hotmail.de> wrote:Currently, accoring to N3690, pack-expansion-captures can't use the initializer form. From §5.1.2 [prim.expr.lambda] / 14:A simple-capture followed by an ellipsis is a pack expansion (14.5.3). An init-capture followed by an ellipsis is ill-formed.
The problem with this is that we may be able to say `[up = std::move(up)]{ ... }` now, but we still can't capture a pack where one of the objects is of a move-only type, leaving us with the same problem we had in C++11, just with packs instead of individual captures now.
Is there a reason why `[xargs = std::move(args)...]{ ... }` was disallowed? The choice doesn't seem particularly arbitary, considering that it was explicitly spelled out.
Additionally, is there already any discussion about changing this so pack-expansion with init-captures is allowed?One problem here is that an init-capture introduces a *named* member of the closure type. A class member name that names a pack would be a new notion, and would bring with it significant additional complications (such as the inability to determine syntactically whether a construct contains an unexpanded parameter pack).That said, I think it was a mistake to describe init-captures as introducing a /named/ member of the closure type. I don't think it solves the problem it was intended to solve (that is, making the name visible within the body of the lambda) because lookup within the lambda during the initial parse does not find names in the closure type, and the core language might be clearer if they also introduced unnamed members. As such, the above problem is largely artificial, and the difference between init-captures and simple-captures is jarring and doesn't seem to represent any fundamental limitation.I think a paper exploring these issues and proposing to allow pack-expansions of init-captures would be interesting. It would presumably need to either generalize function parameter packs to also cover init-captures, or to introduce a new form of parameter pack. One strawman possibility, to demonstrate that there's no fundamental problem here, would be to desugar init-captures differently:[a(x)..., b] { ... }could be represented as[&](auto ...a) mutable { return [b] { ... }; }(x...)
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-discussio...@isocpp.org.
To post to this group, send email to std-dis...@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-discussion/.