How to const-overload opEquals(R)(R rhs)?
Tobias Pankrath
tobias at pankrath.net
Tue Aug 7 09:50:22 PDT 2012
On Tuesday, 7 August 2012 at 16:46:04 UTC, Ali Çehreli wrote:
> 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
Design & Style aside. Shouldn't this be possible?
I do have std.Tuple in mind, which can have members of any type.
If one of these does not have a const opEquals, comparison is
unnecessary restricted to mutable instances.
More information about the Digitalmars-d-learn
mailing list