[Issue 8681] dmd accepts mutable AA key types for objects
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Jul 8 20:10:40 PDT 2013
http://d.puremagic.com/issues/show_bug.cgi?id=8681
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 20:10:39 PDT ---
There's a case where accepting mutable keys may be OK:
class C {
immutable int x;
int y, z;
this() { ... /* initialize x */ }
size_t toHash() const {
// The "real" data is in x; y and z are used for, e.g., caching
// or holding temporary values
return typeid(int).getHash(x);
}
bool opEquals(const C c) const {
return x == c.x;
}
}
Since both toHash and opEquals only depend on C.x, it should be permissible to
accept mutable C as AA key; the immutability of C.x guarantees we won't run
into problems.
The problem is, I don't think such a case is expressible in the current type
system.
(Though arguably, such cases are probably bad design and shouldn't be
encouraged/catered to.)
--
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