Agreed.

+1

 

Move semantics should be easier, as they also give C++ the performance edge over Java etc.

 

From: Fabio Alemagna via Std-Proposals
Sent: 17 May 2022 16:05
To: std-proposals@lists.isocpp.org
Cc: Fabio Alemagna
Subject: [std-proposals] Easier syntax for move-capture in lambdas

 

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
discussions/proposals.

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 */
    }

Thoughts?

Regards,
Fabio
--
Std-Proposals mailing list
Std-Proposals@lists.isocpp.org
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals