I agree, and I doubt it was intentional. if (arr) should mean if (arr.length && arr.ptr) But since you can only get (arr.length != 0 && arr.ptr == null) when doing unsafe things with arrays, I think it's entirely reasonable to use if (arr) -> if (arr.length)
This is what I expected. Much like with class references, distinguishing between null and empty is not '=='s job, that is what 'is' is for. "Timon Gehr" <[email protected]> wrote in message news:[email protected]... > 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.
