InternetAddress comparison fail
Jonathan Marler via Digitalmars-d
digitalmars-d at puremagic.com
Sat Jan 3 08:33:54 PST 2015
On Saturday, 3 January 2015 at 06:01:24 UTC, Steven Schveighoffer
wrote:
> On 1/3/15 12:51 AM, Jon wrote:
>> On Saturday, 3 January 2015 at 05:40:33 UTC, Steven
>> Schveighoffer wrote:
>>> On 1/3/15 12:32 AM, Jon wrote:
>>>
>>>> Still, shouldn't the == operator do a deep compare of the two
>>>> InternetAddress objects in the absence of a defined opEquals
>>>> method? I
>>>> don't see why it should fail in the above example.
>>>
>>> InternetAddress is a class. Default comparison for class is
>>> identity
>>> (refer to the same object).
>>>
>>> -Steve
>>
>> Thanks for clearing that up - it's been a while since I've
>> played with
>> D. Maybe back in D1 it did a deep compare?
>>
>> The docs still refer to == as doing a comparison of the
>> object's
>> contents though, unless I'm misreading it.
>>
>> Under http://dlang.org/expression: "For class objects, the ==
>> and !=
>> operators compare the contents of the objects." Maybe this
>> needs to be
>> updated.
>
> I can see how the wording is confusing, but that statement is
> somewhat out of context. What it really means is that == and !=
> *should* be comparing the contents.
>
> It is an explanatory statement as to why you cannot call
>
> obj == null;
>
> Because this translates to obj.opEquals(null), if obj is null,
> then it crashes (well, at least it used to).
>
> The true definition of the default is here:
>
> https://github.com/schveiguy/druntime/blob/master/src/object_.d#L107
>
> -Steve
So what is the right way to compare the contents of 2 classes? I
thought it was to implement an opEquals method. It pains me to
see people using the toAddrString function to compare Address
classes:( This is so inefficient and unnecessary.
More information about the Digitalmars-d
mailing list