why @property cannot be pass as ref ?

Ali Çehreli acehreli at yahoo.com
Wed Dec 20 18:43:21 UTC 2017


Thanks to Mengü for linking to that section. I have to make corrections 
below.

On 12/20/2017 10:04 AM, Ali Çehreli wrote:

 > 'auto ref' essentially generates two copies of the function: one taking
 > by-value for rvalues

Note that by-value for rvalues means "blitting" in D (blit: bit-level 
transfer).

 > in the case of
 > rvalues its a local variable (copy of the actual argument).

I was wrong there: The local variable is the actual argument blitted in 
to the function.

The post-blit is never executed for rvalues. The following program does 
*not* print "post-blit":

import std.stdio;

struct S {
     int i;
     this (int i) {
         this.i = i;
         writeln("&this  : ", &this);
     }

     this(this) {
         writeln("post-blit");
     }
}

void foo()(auto ref S s) {
     writeln("&s     : ", &s);
}

void main() {
     auto lvalue = S(1);
     foo(lvalue);
     foo(S(2)); // rvalue
}

&this  : 7FFF23ED08A8    <-- lvalue
&s     : 7FFF23ED08A8    <-- by-ref lvalue
&this  : 7FFF23ED08AC    <-- rvalue
&s     : 7FFF23ED0890    <-- blitted rvalue

Ali



More information about the Digitalmars-d-learn mailing list