
15 Mar
2005
15 Mar
'05
8:31 p.m.
Dave Harris wrote:
This was specifically an issue with optional or alternate types. For example, I had something similar to:
size_t MyType::hash_value() const { return use_a ? hash_value(a) : hash_value(b); }
where a and b could be different types.
This is because you ignored the "use_a" member when computing the hash value. We can't prevent these mistakes in general; if you omit a member (that affects the equivalence relation) when computing the hash value, the computation is just wrong. A hash_value that encodes the type will just hide the error from you if a and b have different types; this will bite you (or someone else) later if/when b is changed to have the same type as a.