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?

For structs it provides memberwise comparison for classes it uses pointer-identity

Reply via email to