Default implementation of opEquals

Mark via Digitalmars-d digitalmars-d at puremagic.com
Fri Oct 7 05:04:09 PDT 2016


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?


More information about the Digitalmars-d mailing list