Postfix const works, but prefix version doesn't work
struct Tuple(Specs...)
{
Specs field;
bool opEquals(R)(R rhs) { return true; }
// bool opEquals(R)(R rhs) const { return true; } // OK
const bool opEquals(R)(R rhs) { return true; } // NG
}
void main()
{
Tuple!(size_t, size_t) t;
assert(t == t); // line 14
}
output:
test.d(14): Error: template test.Tuple!(uint,uint).Tuple.opEquals matches more than one template declaration, test.d(5):opEquals(R) and test.d(8):opEquals(R)
Comment #1 by k.hara.pg — 2012-08-08T08:51:16Z
More explainable test case.
struct Point
{
bool opEquals(R)(R rhs) { return true; }
bool opEquals(R)(R rhs) const { return true; }
}
void main()
{
Point mp;
const Point cp;
assert(mp == mp);
assert(mp == cp);
assert(cp == mp); // doesn't work
assert(cp == cp); // doesn't work
}
If the left hand side of '==' is const value, const opEquals never matches.