Reputation: 30168
I like new C++14 addition of giving lambdas ability to capture move only arguments, but I am not a fan of the syntax:
Move capture in lambda
What is a a reason that simpler
auto f = [&&x]{return x->twenty_perc_cooler();};
was not used?
Upvotes: 3
Views: 150
Reputation: 961
This issue was actually addressed in N3610, a proposal regarding capture-by-move:
Why not capture with &&?
It's often asked why we wouldn't just support something like
[&&x] { ... }
The issue here is that we're not capturing by an rvalue reference, we are attempting to move. If we would capture by rvalue reference, the move would occur too late, since it's intended to happen at capture time, not at call time. And as long as we're capturing something that has a name, we shouldn't do a hidden move from it.
Upvotes: 4