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

Sönke Ludwig via Digitalmars-d digitalmars-d at puremagic.com
Mon Feb 1 05:32:42 PST 2016


Am 01.02.2016 um 14:21 schrieb Shachar Shemesh:
> Hi all,
>
> I have a non-copyable struct with move semantics. In other words, a
> struct with @disable this(this), but with working overloads for the
> this(copy) and opAssign.
>
> Now I have an instance of that struct. I would like to be able to
> voluntarily give up ownership for the sake of another instance.
>
> In C++, I would do something like this:
>
> unique_ptr<int> p (new int), q;
>
> q = std::move(p);
>
> I am unsure what is the correct way to do this under D.
>
> Shachar

Should work with move() from std.algorithm:
http://dlang.org/library/std/algorithm/mutation/move.html


More information about the Digitalmars-d mailing list