D's equivalent to C++'s std::move?
Ola Fosheim Grøstad via Digitalmars-d
digitalmars-d at puremagic.com
Wed Feb 3 07:29:33 PST 2016
On Wednesday, 3 February 2016 at 15:05:39 UTC, Sönke Ludwig wrote:
> For std.move, isn't the only place where an exception can be
> thrown in the destructor (which shouldn't throw)? It uses
> memcpy to move the memory around to circumvent any extended
> construction logic.
Not sure if you are talking about something else, but in C++ if
you do
"somefunction(std::move(resource))"
then somefunction can throw and the resource remains untouched
(if implemented in a reasonable fashion).
In D, std.move(...) has this implementation:
private T moveImpl(T)(ref T source)
{
T result = void;
moveEmplace(source, result);
return result;
}
So clearly by the time somefunction is called, the resource is
already moved and an exception will cause permanent damage?
More information about the Digitalmars-d
mailing list