Possible @property compromise

TommiT tommitissari at hotmail.com
Thu Jan 31 14:07:12 PST 2013


On Thursday, 31 January 2013 at 19:13:03 UTC, Zach the Mystic 
wrote:
> I'm hoping that the community won't close the books on this 
> issue without even *examining* my proposal, found here:
>
> http://forum.dlang.org/thread/kdukid$stg$1@digitalmars.com?page=2#post-yqvrjszzlcpmmuyqyxdz:40forum.dlang.org


I'm just going to repeat the arguments I've already made on the 
"Property discussion wrap-up" thread against the idea of using a 
variable as a property:

struct MyArray
{
     int _len;

     // struct2.0 variables have an implicit reference 'outer' to
     // the enclosing object (don't ask how... not my idea)

     struct2.0 Len
     {
         int opCall() const
         {
             return outer._len;
         }

         alias this = opCall;

         void opAssign(int v) const
         {
             outer._len = v;
         }
     }

     Len length; // please ignore the memory overhead over here
}

void func(N)(N n)
     if (isConvertible!(N,int))
{
     n = 123;
}

void main()
{
     MyArray arr;
     func(arr.length); // changes arr._len (not good)
}



More information about the Digitalmars-d mailing list