Discussion Thread: DIP 1040--Copying, Moving, and Forwarding--Community Review Round 1

Walter Bright newshound2 at digitalmars.com
Thu Mar 11 03:33:31 UTC 2021


On 3/10/2021 5:27 PM, tsbockman wrote:
> On Thursday, 11 March 2021 at 00:31:01 UTC, deadalnix wrote:
>> On Wednesday, 10 March 2021 at 22:51:58 UTC, tsbockman wrote:
>>> Am I the only one who thinks that it would be better to have syntax that 
>>> accurately reflects the semantics, instead of just documenting "this syntax 
>>> is a lie"?
>>
>> No, I think there is a problem with using opAssign here, because "this" will 
>> refers to something that is possibly uninitialized, and the old value may not 
>> be consumed fully.
>>
>> Due to problem #1, this kinda need to be a constructor rather than an opAssign.

opAssign is only for assigning to initialized objects. Constructors are for 
uninitialized objects.


> Yeah, studying the DIP I can't figure out what problem the move `opAssign` is 
> supposed to solve that the constructor doesn't:
> https://forum.dlang.org/post/kzgybicwqwlfyiiefucc@forum.dlang.org

The thing about "destroy after move" is to deal with the case of both the source 
and the destination referring to the same object. The concern is that destroying 
the destination's original contents first will destroy them for the source 
before it gets moved in.

It's the same problem "swap" has. It's also necessary semantics for a reference 
counted object.


More information about the Digitalmars-d mailing list