Non-null objects, the Null Object pattern, and T.init
    Timon Gehr 
    timon.gehr at gmx.ch
       
    Thu Jan 16 22:18:57 PST 2014
    
    
  
On 01/17/2014 03:11 AM, Adam D. Ruppe wrote:
> On Friday, 17 January 2014 at 02:04:27 UTC, Andrei Alexandrescu wrote:
>> Yah, that would be expected.
>
> Yeah, but I think people would find it weird. This kind of thing is
> actually possible today:
class Foo{ int x = 2; }
class Bar{ auto foo = new Foo(); }
void main(){
     auto ibar = new immutable(Bar)();
     auto bar = new Bar();
     static assert(is(typeof(ibar.foo.x)==immutable));
     assert(ibar.foo.x==2);
     bar.foo.x=3;
     assert(ibar.foo.x==3); // uh-oh!
}
    
    
More information about the Digitalmars-d
mailing list