Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesnt move capture in C++14 use [&&move_me_into_lambda] syntax?

Tags:

lambda

c++14

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?

like image 330
NoSenseEtAl Avatar asked Dec 02 '25 01:12

NoSenseEtAl


1 Answers

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.

like image 141
Philipp Lenk Avatar answered Dec 07 '25 02:12

Philipp Lenk