C++ Logo


Advanced search

[std-proposals] Easier syntax for move-capture in lambdas

From: Fabio Alemagna <falemagn_at_[hidden]>
Date: Tue, 17 May 2022 13:05:11 +0200
I have searched wide and large to see if anything like, or better
than, this has been proposed, but found nothing. Apologies if this has
already been discussed, if so I'd appreciate any pointers to past

In my current project I suddenly found myself having to write lots of
lambdas like this:

    [a = std::move(), b = std::move(b), /*...,*/ n = std::move(n)](/*...*/) {
        /* body */

Those moves are tedious to write and can easily extend too far on the
line, making the code more difficult to read.

I thought it'd be nice if we could just do this, instead:

    [&&a, &&b, /*..., */ &&n](/*...*/) {
        /* body */

And, just like one can use the single ampersand to capture everything
by reference, one could be able to use the double ampersand to capture
everything by moved-to-value:

    [&&](/*...*/) {
        /* body */



Received on 2022-05-17 11:05:23