How to const-overload opEquals(R)(R rhs)?

Ali Çehreli acehreli at yahoo.com
Tue Aug 7 09:46:03 PDT 2012


On 08/07/2012 06:40 AM, Tobias Pankrath wrote:

 > bool opEquals(R)(R rhs) { return x == rhs.x && y == rhs.y; }
 > bool opEquals(R)(R rhs) const { return x == rhs.x && y == rhs.y; }

I strongly recommend that only the const version should be defined. That 
would work on both mutable and immutable objects.

Besides, opEquals should not modify the object anyway; that would be 
surprising.

Ali



More information about the Digitalmars-d-learn mailing list