Default implementation of opEquals

Mark via Digitalmars-d digitalmars-d at puremagic.com
Fri Oct 7 06:41:00 PDT 2016


On Friday, 7 October 2016 at 12:34:34 UTC, Adam D. Ruppe wrote:
> On Friday, 7 October 2016 at 12:04:09 UTC, Mark wrote:
>> "If opEquals is not specified, the compiler provides a default 
>> version that does member-wise comparison"
>
> That's referring to structs. For classes, it gives an identity 
> comparison function here: 
> https://dlang.org/spec/operatoroverloading.html#equals
>
>> Wouldn't member-wise comparison be a more intuitive default?
>
> Classes are supposed to represent encapsulated objects where 
> you don't look at the members from the outside, so that might 
> be surprising in a different way.

Okay, that makes sense.

I find it slightly annoying that the default opCmp throws an 
exception whereas the default opEquals doesn't, but if both of 
these functions are to be removed from Object, as Jonathan M 
Davis stipulates, then all of this is a non-issue.


More information about the Digitalmars-d mailing list