Yeah, that should work for the conditions in if, while, and for loops but won't work for anything else (_maybe_ ternary operators, but I'm not sure). So, if you need to be able to do !obj in the general case, that's not going towork
...
import std.stdio;
struct S {
int x;
bool opCast(T)() if (is(T == bool)) {
return x == 0;
}
}
void main() {
auto s = S(1);
auto b = !s;
writeln(b); // true
}
Is this not supposed to work?
