opEquals default behaviour - poorly documented or am I missing something?
Ali Çehreli via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Nov 17 11:44:35 PST 2015
On 11/17/2015 12:40 AM, MichaelZ wrote:
> 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?
Correct. The behavior for class objects is the following algorithm on
the same page:
http://dlang.org/operatoroverloading.html#equals
This one:
bool opEquals(Object a, Object b)
{
if (a is b) return true;
if (a is null || b is null) return false;
if (typeid(a) == typeid(b)) return a.opEquals(b);
return a.opEquals(b) && b.opEquals(a);
}
Ali
More information about the Digitalmars-d-learn
mailing list