D's equivalent to C++'s std::move?

Sönke Ludwig via Digitalmars-d digitalmars-d at puremagic.com
Wed Feb 3 08:25:53 PST 2016


Am 03.02.2016 um 16:56 schrieb Ola Fosheim Grøstad:
> On Wednesday, 3 February 2016 at 15:44:25 UTC, Sönke Ludwig wrote:
>> seems like pretty clear semantics. And in C++ you'd have the same
>> situation once somefunction decides to move/swap the value somewhere
>> else before throwing an exception.
>
> Well, you can always move it back or wait with the move.

Yeah, a ref parameter is more or less the only similar option.

> Also, std.move may end up being inefficient when you have a complicated
> resource holder. Since the work is done before calling the function the
> optimizer may struggle with getting rid of the work.

That's probably indeed true since it relies on memcpy. You can of course 
still use dynamic allocation + unique reference, or pass-by-reference, 
to avoid the cost of the copy. But it does sound like a worthwhile 
optimization target.


More information about the Digitalmars-d mailing list