Make objects.opEquals a template?
Yuxuan Shui via Digitalmars-d
digitalmars-d at puremagic.com
Sun Jul 12 23:49:09 PDT 2015
The main reason here is to use '==' in @safe code:
class A {
override @safe bool opEquals(Object o) {
return cast(A)o !is null;
}
}
@safe void main() {
A a = new A;
A b = new A;
a == b;
}
This doesn't compile in current D, because objects.opEquals takes
two Object, and Object.opEquals is not @safe.
Why can't we have a template objects.opEquals?
auto opEquals(T, S)(T a, S b) { ... }
More information about the Digitalmars-d
mailing list