Empty field doesn't exist for arrays, right?

2011-03-08 Thread 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

Re: Empty field doesn't exist for arrays, right?

2011-03-08 Thread Andrej Mitrovic
Nevermind, I'm dumb. It's in std.array, I just need to import it. This needs to be said in TDPL however.

Re: Empty field doesn't exist for arrays, right?

2011-03-08 Thread Andrej Mitrovic
On 3/8/11, bearophile bearophileh...@lycos.com wrote: empty is not an array method, it's a free function that is used with a funny syntax. Yes but the compiler doesn't know that until std.array is imported. A better error message is that empty isn't a property of that array. It's much easier to

Re: Empty field doesn't exist for arrays, right?

2011-03-08 Thread Jesse Phillips
Andrej Mitrovic Wrote: On 3/8/11, bearophile bearophileh...@lycos.com wrote: empty is not an array method, it's a free function that is used with a funny syntax. Yes but the compiler doesn't know that until std.array is imported. A better error message is that empty isn't a property of

Re: Empty field doesn't exist for arrays, right?

2011-03-08 Thread Andrej Mitrovic
On 3/8/11, Jesse Phillips jessekphillip...@gmail.com wrote: What if you are trying to create a method which will act as a property for the array? If you get it wrong you would get the error that an array doesn't have the property and scream, I know that is why I'm building a function for it.

Re: Empty field doesn't exist for arrays, right?

2011-03-08 Thread spir
On 03/08/2011 06:56 PM, Andrej Mitrovic wrote: 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):

Re: Empty field doesn't exist for arrays, right?

2011-03-08 Thread Jesse Phillips
Andrej Mitrovic Wrote: On 3/8/11, Jesse Phillips jessekphillip...@gmail.com wrote: What if you are trying to create a method which will act as a property for the array? If you get it wrong you would get the error that an array doesn't have the property and scream, I know that is why I'm

Re: Empty field doesn't exist for arrays, right?

2011-03-08 Thread Andrej Mitrovic
Well, maybe one day we'll have a compiler with lots of front-end customization options (or some nice analysis tools). In any case this topic is done here since post #2. :)