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
Nevermind, I'm dumb. It's in std.array, I just need to import it. This needs to
be said in TDPL however.
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
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
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.
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):
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
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. :)