Default implementation of opEquals
Jack Stouffer via Digitalmars-d
digitalmars-d at puremagic.com
Fri Oct 7 05:33:50 PDT 2016
On Friday, 7 October 2016 at 12:04:09 UTC, Mark wrote:
> I'm going over the Object class methods and I have a few
> concerns about the opEquals method.
>
> First, what should be the default implementation of opEquals?
> The specification (see
> https://dlang.org/spec/operatoroverloading.html#eqcmp) reads:
>
> "If opEquals is not specified, the compiler provides a default
> version that does member-wise comparison"
>
> But this doesn't appear to be the case (at least with dmd). So
> I went and checked the module in
> https://github.com/dlang/druntime/blob/master/src/object.d. It
> implements opEquals by comparing references (obj1 is obj2), not
> by member-wise comparison.
>
> Wouldn't member-wise comparison be a more intuitive default?
This is a problem with the spec that needs to be fixed. It's well
known that member wise comparison default is for structs and
objects just compare the reference. I believe this has always
been the intended behavior.
More information about the Digitalmars-d
mailing list