string <-> null/bool implicit conversion
via Digitalmars-d
digitalmars-d at puremagic.com
Thu Aug 20 09:45:16 PDT 2015
Hi!
string a = "";
string b;
writeln(a ? "a" : "null");
writeln(b ? "b" : "null");
This program outputs:
a
null
What?
I suppose this is by design, but are there any plans to deprecate
this?
I understand this happens because in this context, string.ptr is
evaluated, but should a string really have the semantics of
string.ptr depending on the context?
Having 2 empty strings evaluate differently is very unintuitive
and error-prone, in my opinion.
More information about the Digitalmars-d
mailing list