Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2005-03-15 15:31:55

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.

Boost list run by bdawes at, gregod at, cpdaniel at, john at