Discussion: Rvalue refs and a Move construtor for D

Suleyman sahmi.soulaimane at gmail.com
Thu Sep 5 19:38:57 UTC 2019

On Thursday, 5 September 2019 at 18:59:50 UTC, kinke wrote:

> Resetting the moved-from instance to T.init or something 
> similar is what you'd do in the move ctor anyway (besides 
> blitting the previous contents into the new instance and maybe 
> doing some more adjustments), and definitely what the default 
> implementation of the move ctor would do.

His initial point about the advantage of rvalue still remains 

void foo(@rvalue ref S value, int n = 0)
     if (n > 32)

     foo(__move(value), n + 1);

struct S
     long[10] a;

     import core.stdc.stdio : puts;

     this(@rvalue ref S) { puts("mc"); }
     this(ref S) { puts("cc"); }
     auto opAssign(@rvalue ref S) { puts("m="); }
     auto opAssign(ref S) { puts("c="); }
     ~this() { puts("~"); }

void main()
     S lvalue;

You can try this with the POC. The whole program only calls the 
destructor for the lvalue, and only once. You need a competitive 

More information about the Digitalmars-d mailing list