[Issue 11025] New: std.typecons.Tuple needs to define toHash
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Sep 13 13:14:58 PDT 2013
http://d.puremagic.com/issues/show_bug.cgi?id=11025
Summary: std.typecons.Tuple needs to define toHash
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: normal
Priority: P2
Component: Phobos
AssignedTo: nobody at puremagic.com
ReportedBy: hsteoh at quickfur.ath.cx
--- Comment #0 from hsteoh at quickfur.ath.cx 2013-09-13 13:14:57 PDT ---
Code:
------
import std.typecons;
void main() {
bool[Tuple!(string,string)] aa;
aa[tuple("a", "b")] = true;
assert(tuple("a", "b") in aa); // OK due to folding of identical string
literals
assert(tuple("a".idup, "b".idup) in aa); // NG
}
------
Proof that toHash is the problem:
------
import std.typecons, std.stdio;
void main() {
auto t = tuple("a", "b");
auto u = tuple("a".idup, "b".idup);
writeln(typeid(t).getHash(&t)); // prints 18075234133232566449
writeln(typeid(u).getHash(&u)); // prints 5823865589096027868
}
------
It appears that the hash is computed only on the binary representation of the
tuple, not on the contents of each field. This causes the AA breakage above.
--
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