Andrej Mitrovic:

> 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:

You need this at the top:
import std.array;


> 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. 

emopty is not an array method, it's a free function that is used with a funny 
syntax.

Bye,
bearophile

Reply via email to