Discussion: Rvalue refs and a Move construtor for D

RazvanN razvan.nitu1305 at gmail.com
Thu Sep 5 08:29:23 UTC 2019


On Tuesday, 3 September 2019 at 01:07:18 UTC, Suleyman wrote:
> I updated the POC.
>
> You can now declare the move constructor & move opAssing like 
> the following:
>
> ```
> struct S
> {
>     this(ref S) @move {}     // move constructor
>     opAssign(ref S) @move {} // move opAssign
> }
> ```
>
> Or with rvalue ref:
>
> ```
> struct S
> {
>     this(@rvalue ref S) {}     // move constructor
>     opAssign(@rvalue ref S) {} // move opAssign
> }
> ```
>
> All implementations use rvalue ref internally. It's just a 
> matter of exposing in the language it or not.

Why not define the move constructor like this:

this(S rhs) {}

I know it takes by value, but up until now it has been referred 
to as rvalue constructor. Behind the scenes the compiler will 
treat it as a move constructor and therefore will take the first 
parameter by ref. Now we have a clear distinction between copy 
constructor and move constructor. It should probably be in a 
different overload set than the other constructors.


More information about the Digitalmars-d mailing list