opEquals default behaviour - poorly documented or am I missing something?
MichaelZ via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Nov 17 00:40:49 PST 2015
In http://dlang.org/operatoroverloading.html#eqcmp it is stated
that
"If opEquals is not specified, the compiler provides a default
version that does member-wise comparison."
However, doesn't this only apply to structs, and not objects?
The default behaviour of opEquals for objects seems to be "is".
A few paragraphs later, in
http://dlang.org/operatoroverloading.html#compare, the
description of the default version is repeated:
""
If overriding Object.opCmp() for classes, the class member
function signature should look like:
...
If structs declare an opCmp member function, it should have the
following form:
...
Note that opCmp is only used for the inequality operators;
expressions like a == b always uses opEquals. **If opCmp is
defined but opEquals isn't, the compiler will supply a default
version of opEquals that performs member-wise comparison.**
""
Even here, the fact that the described default opEquals behaviour
appears to only apply to structs is far from clear.
Or am I missing something that should be obvious?
Thanks,
-- MichaelZ
More information about the Digitalmars-d-learn
mailing list