www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - null Rebindable

reply bearophile <bearophileHUGS lycos.com> writes:
This D2 program shows that you can't test if a class reference wrapped with
Rebindable is null:


import std.typecons;
const class Foo {}
void main() {
    auto a = Rebindable!Foo(new Foo);
    a = new Foo;
    assert(a !is null); // err
}


DMD 2.050 generates:
test.d(6): Error: incompatible types for ((a) !is (null)):
'Rebindable!(const(Foo))' and 'void*'


Is this the currently correct way to do it? (It works):

assert(a.get() !is null); // OK

I have seen the get() method is not documented on the site, so is that a
temporary limitation caused by the unfinished "alis this" implementation?

Bye and thank you,
bearophile
Nov 21 2010
parent Jonathan M Davis <jmdavisProg gmx.com> writes:
On Sunday 21 November 2010 16:19:27 bearophile wrote:
 This D2 program shows that you can't test if a class reference wrapped with
 Rebindable is null:
 
 
 import std.typecons;
 const class Foo {}
 void main() {
     auto a = Rebindable!Foo(new Foo);
     a = new Foo;
     assert(a !is null); // err
 }
 
 
 DMD 2.050 generates:
 test.d(6): Error: incompatible types for ((a) !is (null)):
 'Rebindable!(const(Foo))' and 'void*'
 
 
 Is this the currently correct way to do it? (It works):
 
 assert(a.get() !is null); // OK
 
 I have seen the get() method is not documented on the site, so is that a
 temporary limitation caused by the unfinished "alis this" implementation?
 
 Bye and thank you,
 bearophile
(a.get !is null) works. Why it's not documented, I don't know, and whether (a !is null) will ever be able to work with alias this, I don't know. I just know that (a.get !is null) currently works. - Jonathan M Davis
Nov 21 2010