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

tsbockman thomas.bockman at gmail.com
Thu Mar 11 04:17:48 UTC 2021


On Thursday, 11 March 2021 at 03:33:31 UTC, Walter Bright wrote:
> On 3/10/2021 5:27 PM, tsbockman wrote:
>> 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.

Wouldn't it make more sense to just skip the move operation 
entirely when the source and destination are the same? Or are 
there circumstances in which that cannot be determined, even at 
runtime?

Also, doesn't this mean that every move of an object with a 
destructor requires a copy? Does the copy constructor get called 
in such cases? If so, what benefit do moves have over copies? If 
not, how do you know you're not breaking assumptions that the 
destructor depends upon for correct functioning by making this 
the one circumstance in which a value may be copied without 
calling its copy constructor? Which function sees the "real" 
address of the object: the move operator, or the destructor?


More information about the Digitalmars-d mailing list