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

via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Jul 30 03:36:14 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)....

Hmm... are you implying that `opAssign(ref T other)` should be 
disallowed? Why? I find this the obvious way to implement move 
semantics, and it is also what std.algorithm.move does:

http://dlang.org/phobos/std_algorithm_mutation.html#.move


More information about the Digitalmars-d-learn mailing list