[Issue 10525] Struct as key in Associative array ignores value semantics
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Jul 8 15:09:41 PDT 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10525
hsteoh at quickfur.ath.cx changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |hsteoh at quickfur.ath.cx
--- Comment #1 from hsteoh at quickfur.ath.cx 2013-07-08 15:09:40 PDT ---
This is not really a bug. Structs by default are bitwise-compared.
If you want structs to be deep-compared, you need to define toHash and opCmp:
struct S {
char[] str;
size_t toHash() const {
// Just use arrays' builtin hash function, no need to reinvent your own
return typeid(str).getHash(&str);
}
// Note: this exact function signature must be used;
// DMD is currently very picky about this.
int opCmp(ref const S s) const {
return typeid(str).compare(&str, &s.str);
}
}
Once these two pieces are in place, your struct should work correctly as AA
key.
--
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