Default implementation of class .opEquals?
H. S. Teoh
hsteoh at quickfur.ath.cx
Thu Apr 16 17:21:15 UTC 2020
Just out of curiosity, is there a mixin template or something like that
in Phobos for implementing a default .opEquals that does member-wise
comparison of a class object? Something like this:
mixin template DefaultOpEquals(T) {
bool opEquals(Object o) {
auto t = cast(T) o;
if (t is null) return false;
foreach (field; __traits(getAllMembers, T)) {
if (this.field != t.field) return false;
}
return true;
}
}
It's annoying to have to write an .opEquals method for every class that
basically just does the same thing.
T
--
Verbing weirds language. -- Calvin (& Hobbes)
More information about the Digitalmars-d
mailing list