[Issue 3433] [tdpl] Comparing structs for equality is not member-by-member
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Oct 21 08:47:18 PDT 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3433
David Simcha <dsimcha at yahoo.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |dsimcha at yahoo.com
--- Comment #2 from David Simcha <dsimcha at yahoo.com> 2009-10-21 08:47:16 PDT ---
Not sure if bitwise comparison should or shouldn't be the default, this is
subjective. However, I'd say this could be solved, along with several similar
problems, by a function in a new Phobos module called std.mixin:
// Disclaimer: Quick and dirty, not tested.
enum equalsByOpEquals = q{
bool opEquals(typeof(this) rhs) {
foreach(tupleIndex, elem; this.tupleof) {
if(rhs.tupleof[tupleIndex] != elem) {
return false;
}
}
return true;
}
}
Usage:
struct MyStruct {
mixin(equalsByOpEquals);
// Other stuff.
}
We could also define a bunch of other stuff like a generic comparison operator
for when you only need some arbitrary total ordering for binary searches, etc.
and don't particularly care what that ordering is.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list