bug? alias this <-> opDispatch interaction
Jonathan M Davis
jmdavisProg at gmx.com
Sat Nov 9 21:50:38 PST 2013
On Sunday, November 10, 2013 05:58:53 Meta wrote:
> On Sunday, 10 November 2013 at 00:47:33 UTC, Luís Marques wrote:
> > 1: T[string] foo;
> > 2: foo[""] = new T;
> > 3: foo[null] = new T;
> >
> > Lines 2 and 3 seem to do the same, apparently. People seemed to
> > agree that 3 should not be relied upon (should it?), but if I
> > recall/understand it was not totally clear to people why 2 and
> > 3 *do* do the same thing, so feel free to clarify.
>
> 2 and 3 do the same thing because an empty slice is the same as
> null. I personally think this is a bad thing.
Actually, "" isn't null. They're equal, but they aren't the same. [] and null
are the same, but "" isn't the same, because it's a string literal, and string
literals have a byte with '\0' one past their end so that they can be passed
directly to C functions. Now, for the purposes of AAs, "" and null would be
equivalent, because
assert("" == null);
but
assert("" !is null);
- Jonathan M Davis
More information about the Digitalmars-d
mailing list