Move Constructor Syntax

Walter Bright newshound2 at digitalmars.com
Sat Oct 12 00:13:06 UTC 2024


On 10/10/2024 11:48 PM, Manu wrote:
> They initialise an S from another S... I'm not sure what you mean by "they do 
> different things"?

One moves the data (destroying the original), the other copies it (both remain 
valid). If they did the same thing, there'd be no purpose to a move constructor.


> I've been wondering, why do you need to detect that a constructor is a copy or 
> move constructor?

Because they do fundamentally different things.

> That concept seems like a big internal hack. Why do normal 
> overload selection semantics fail to determine the proper selection?

As discussed before, the current compiler allow for "rvalue constructors", which 
do a copy construction. There's also "rvalue reference" semantics which also 
conflate move with copy. And don't forget implicit conversions!

> It's not clear why it's useful or important that copy and move constructors are 
> separate from all other constructors? They're not special; they just happen to 
> accept a self-type as an init argument...

They already exist and are called rvalue constructors. They don't do a move.

> the only reason I can think, is to 
> identify the case where they're not present, and some copy/move code must by 
> synthesised in lieu... what else hangs off that knowledge?

They are special. I left C++ before they added move constructors, with their own 
syntax (rvalue references). I suspect they ran into the same problems.



More information about the Digitalmars-d mailing list