module test; struct MyArray(T) { private T[] data; bool opCast(T)() if (is(T == bool)) { return !data.empty; } }
void main() { auto foo = MyArray!(int)(); auto state = foo ? true : false; } test.d(13): Error: undefined identifier module test.empty test.d(20): Error: template instance test.MyArray!(int).MyArray.opCast!(bool) error instantiating This is straight from the book. Did .empty exist for arrays before? Perhaps this was just a typo in the book, and it was supposed to be: bool opCast(T)() if (is(T == bool)) { return data.length != 0; } Also, that error message *really* needs to improve. It's not module 'test' which is missing the method, it's 'data'. This is one of the most confusing error messages that I know of and it pops up all the time.