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

Walter Bright newshound2 at digitalmars.com
Mon Mar 15 07:48:04 UTC 2021


On 3/12/2021 4:38 AM, deadalnix wrote:
> On Friday, 12 March 2021 at 10:07:41 UTC, Walter Bright wrote:
>> On 3/11/2021 4:53 PM, deadalnix wrote:
>>> On Thursday, 11 March 2021 at 21:41:59 UTC, Walter Bright wrote:
>>>> Why? There can be no other uses of the rvalue, so why not simply move it?
>>>
>>> If you have two objects in your move constructor, but only one at the end, 
>>> then a destruction must take place somewhere.
>>
>> The whole point of move construction is to move an initialized object to an 
>> unconstructed object. No destruction is needed.
>>
>> It's move assignment that needs to destruct something (the original value of 
>> the destination).
> 
> How do you ensures that there aren't any leftover that need to be destroyed or 
> enforce that there are no leftovers?

I don't see any way to do that. When you write a custom destructor, the compiler 
can't verify it, either.

> Enforcing it seems like an impossible task 
> to be, or at least extremely complex. So that means you need to call the 
> destructor anyways and that forces the struct to have a null state.

Both the move constructor and the destructor are in the same struct, and should 
be developed at the same time. At some point, the program has to rely on the 
programmer knowing what he's doing when doing storage management.



More information about the Digitalmars-d mailing list