empty arrays and cast(bool): WAT

Timon Gehr timon.gehr at gmx.ch
Sat Feb 18 18:01:55 PST 2012


Why does the following code behave funny?

void main(){
     string x = " "[1..1];
     writeln(cast(bool)x); // true
     char[] y = [' '][1..1];
     writeln(cast(bool)y); // false
}

Is there any reason for empty arrays to evaluate to true? This is very 
bug prone.


More information about the Digitalmars-d mailing list