On Mon, 14 May 2012 12:08:17 +0200, Gor Gyolchanyan
<[email protected]> wrote:
Hi! I have a small question:
Is the test for a null array equivalent to a test for zero-length array?
This is particularly interesting for strings.
For instance, I could return an empty string from a toString-like
function
and the empty string would be printed, but If I returned a null string,
that would indicate, that there is no string representation and it would
cause some default string to be printed.
So, the question is, if a null array is any different from an empty
array?
This passes. null and [] is a null string, but "" gives a non-null string.
Tested on dmd-head and 2.059.
void main() {
string s1 = null;
assert(s1 is null);
assert(s1.length == 0);
assert(s1.ptr is null);
assert(s1 == []);
assert(s1 == "");
string s2 = [];
assert(s2 is null);
assert(s2.length == 0);
assert(s2.ptr is null);
assert(s2 == []);
assert(s2 == "");
string s3 = "";
assert(s3 !is null);
assert(s3.length == 0);
assert(s3.ptr !is null);
assert(s3 == []);
assert(s3 == "");
}