C++ Logo

std-proposals

Advanced search

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

From: Abdullah Qasim <iamminecraftredstoner_at_[hidden]>
Date: Thu, 26 May 2022 07:23:35 +0000
Agreed.
+1

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

From: Fabio Alemagna via Std-Proposals<mailto:std-proposals_at_[hidden]>
Sent: 17 May 2022 16:05
To: std-proposals_at_[hidden]<mailto:std-proposals_at_[hidden]>
Cc: Fabio Alemagna<mailto:falemagn_at_[hidden]>
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_at_[hidden]
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2022-05-26 07:23:39