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

tsbockman thomas.bockman at gmail.com
Fri Mar 5 23:03:57 UTC 2021


On Friday, 5 March 2021 at 12:19:54 UTC, Mike Parker wrote:
> This is the discussion thread for the first round of Community 
> Review of DIP 1040, "Copying, Moving, and Forwarding":

 From the DIP:
> A Move Constructor for struct S is declared as:
>     this(S s) { ... }
> A Move Assignment Operator for struct S is declared as:
>     void opAssign(S s) { ... }

Is the parameter to these methods really pass-by-value?

If so, why??? Making a copy during every move seems unnecessary, 
and very inefficient. Moreover, for types that define a copy 
constructor, it could reasonably be argued that calling it OR not 
calling it BOTH violate the principle of least surprise. I expect 
moves NOT to call the copy constructor, but I expect 
pass-by-value WILL call it: a contradiction.

If the parameter is, in fact, intended to be pass-by-reference, 
then I must strenuously object to the chosen syntax. Please do 
not make this the one-and-only place in the entire language where 
the pass-by-value syntax secretly means pass-by-reference. The 
fact that `this(ref typeof(this))` is already taken by copy 
constructors is NOT a good reason to violate the established 
semantics of parameter lists in D. Just use a template parameter 
to distinguish them, or something.


More information about the Digitalmars-d mailing list