Default implementation of opEquals

Adam D. Ruppe via Digitalmars-d digitalmars-d at puremagic.com
Fri Oct 7 05:34:34 PDT 2016


On Friday, 7 October 2016 at 12:04:09 UTC, Mark wrote:
> "If opEquals is not specified, the compiler provides a default 
> version that does member-wise comparison"

That's referring to structs. For classes, it gives an identity 
comparison function here: 
https://dlang.org/spec/operatoroverloading.html#equals

> Wouldn't member-wise comparison be a more intuitive default?

Classes are supposed to represent encapsulated objects where you 
don't look at the members from the outside, so that might be 
surprising in a different way.


More information about the Digitalmars-d mailing list