Yeah, that's what you get when you press the wrong buttons. :p Anyways, Rebindable should be castable to bool, to allow for the idiom Rebindable!T foo; if (foo) {}. Addition to typecons.d, line 747: T opCast(T : bool)() { return original !is null; }
Actually, it's explicitly castable to bool: Rebindable!(const Object) r; if (cast(bool) r) assert(0); r = new Object; if (!cast(bool) r) assert(0); But dmd doesn't forward implicit boolean conversions in if (or other) conditions to Rebindable's alias-this object. Reported: bug 5020.
This is dmd issue. Fixing bug5020 is incomplete, so property function + alias this is not implicitly convertible to bool. ---- struct Rebindable { Object obj; @property const(Object) get(){ return obj; } alias get this; } Rebindable r; if (r) assert(0); r.obj = new Object; if (!r) assert(0); ----
Posted pull request: https://github.com/D-Programming-Language/dmd/pull/281
https://github.com/D-Programming-Language/dmd/commit/f70793ba34e4c4365eda7a33e3c073a7b13002a6
*** Issue 5256 has been marked as a duplicate of this issue. ***