Move construction from !is(T == typeof(this))

Stanislav Blinov via Digitalmars-d digitalmars-d at puremagic.com
Wed Apr 26 17:17:27 PDT 2017


On Wednesday, 26 April 2017 at 13:38:59 UTC, Steven Schveighoffer 
wrote:

>>     ~this()
>>     {
>>         data.destroy();
>>     }
>
> Don't do this. It's not a good idea, since data could be 
> invalid at this point. In this case, destroy does nothing (it 
> just sets the array to null), so I would just leave the 
> destructor out of it.

Yeah, sorry, got carried away. Postblit would've been enough for 
enabling destructive move.

> If you want to duplicate const data, but just shallow-copy 
> mutable data, you are correct in that you need two separate 
> constructors, and inout doesn't come into play.

That's the thing, this is more about "need" than "want". As far 
as I understood, Manu is talking about these ctors from the C++ 
perspective, where the copy constructor takes const&.
And the problem for those who come from C++ would be that in D it 
doesn't work that way, at least not universally.


More information about the Digitalmars-d mailing list