scope ref const(T) --> error?!

Ali Çehreli acehreli at yahoo.com
Thu May 3 15:25:45 PDT 2012


On 05/03/2012 03:21 PM, Tove wrote:
 > On Thursday, 3 May 2012 at 18:28:19 UTC, Mehrdad wrote:
 >> What's wrong with passing a struct as scope ref const?
 >>
 >> I want to avoid copying the struct, and its information is only read
 >> inside the function...
 >
 > ref scope? hm? What additional semantics do you desire from that
 > construct, which 'const ref' doesn't provide?

scope is a not-yet-implemented promise of the function. It says: "trust 
me, I will not use this reference outside of the function."

 > A a;
 >
 > void fun(const scope ref A x)
 > {
 > // x goes out of scope, destroy it... oops it's a global variable!?

scope does not destroy. scope makes this illegal (assuming that A is a 
class type):

     a = x;

There is deprecated use of the 'scope' keyword but this is not it.

 > }
 >
 > fun(a);
 >

Ali



More information about the Digitalmars-d mailing list