Struct that destroys its original handle on copy-by-value

Vlad Levenfeld via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Jul 29 12:27:24 PDT 2015


On Wednesday, 29 July 2015 at 19:10:36 UTC, Adam D. Ruppe wrote:
> On Sunday, 26 July 2015 at 12:16:30 UTC, Joseph Rushton 
> Wakeling wrote:
>> My aim by contrast is to _allow_ that kind of use, but render 
>> the original handle empty when it's done.
>
> I don't think D offers any way to do that. With the disabled 
> postblit, you can force people into a method you write that 
> returns a new copy and clears the original, but that won't just 
> work with assignment.
>
> The ref assign might not be forbidden by the written doc but 
> I'm guessing that is just an oversight - struct assignment in D
>  never clears the original, it is always a simple copy (perhaps 
> plus other code)....

Slightly OT, but this is something that would be possible with a 
copy constructor, I think?


More information about the Digitalmars-d-learn mailing list