Operator overloading, structs

Yigal Chripun yigal100 at gmail.com
Thu Jun 4 12:46:32 PDT 2009


bearophile wrote:
> Yigal Chripun:
>> that is an implicit cast.
>> what I'm saying is that:
>>
>>   int a = .. ;
>>   if (a) { .. }
>>
>> this should be a compiler error IMO.
> 
> I think the opposite is good: that empty collections are "false", so the following ones print X:
> 
> int[]  a;
> if (!a) printf("X");
> Set!(int) s;
> if (!s) printf("X");
> int[string] aa;
> if (!aa) printf("X");
> 
> Bye,
> bearophile

what's so bad about using a general collection.empty() API?
 > int[]  a;
 > if (!a.empty) printf("X");
 > Set!(int) s;
 > if (!s.empty) printf("X");
 > int[string] aa;
 > if (!aa.empty) printf("X");

what's more readable, my version or yours?



More information about the Digitalmars-d mailing list