Discussion Thread: DIP 1040--Copying, Moving, and Forwarding--Community Review Round 1
Walter Bright
newshound2 at digitalmars.com
Thu Mar 11 08:42:32 UTC 2021
On 3/10/2021 11:44 PM, Arafel wrote:
> There is another issue with the proposed semantics, unless I'm missing something.
>
> How can I implement both an "identity assignment operator" [1] and a "move
> assignment operator"? The proposed syntax is co-opting an existing pattern for a
> different use case.
>
> Let's say I have a struct that includes an associative array, where I implement
> deep copy for the assignment operator.
>
> Will in this case my deep copy be reused automatically for movement? That's
> obviously not what I want, for that I'd just want to copy the reference to the
> existing AA.
>
> If anything, this should be added to the breaking changes and deprecations, or
> at least mentioned as something to check for.
>
> I could have used a `ref` parameter, but this wouldn't work with rvalues, and in
> any case the syntax is currently allowed, unlike constructors (bug 20424 [2])
> which are mentioned in the DIP... although even there I tend to agree with
> comment #5, but I digress.
>
> [1]: https://dlang.org/spec/operatoroverloading.html#assignment
> [2]: https://issues.dlang.org/show_bug.cgi?id=20424
Constructing from an rvalue essentially is move construction.
More information about the Digitalmars-d
mailing list