D's equivalent to C++'s std::move?
Ola Fosheim Grøstad via Digitalmars-d
digitalmars-d at puremagic.com
Tue Feb 2 14:46:23 PST 2016
On Tuesday, 2 February 2016 at 21:18:27 UTC, maik klein wrote:
> Could you share this? I would be very interested in how you
> have approached it.
My ad hoc pointer experiments try to be general and is
convoluted, so not the best example. The basic idea is to have a
pointer type that match "&&" in C++ (which cannot be done
completely).
So we have something like:
struct moving(T){
T* ptr;
~this(){ assert(ptr is null); } // optional check to ensure
that the move is completed
}
then have a move() function that returns a moving!T struct
In you pointer struct you match opAssign(moving!T ...) to emulate
"operator=(T&& ...)" and set the ptr field to null to prevent it
from being used again (if you want that extra check).
More information about the Digitalmars-d
mailing list