From: Dave Harris (brangdon_at_[hidden])
Date: 2005-03-16 12:07:14
pdimov_at_[hidden] (Peter Dimov) wrote (abridged):
> You also need equal_ptr<MyType>.
> Also, it is easy to break the above unordered_set my modifying some
> of the MyTypes.
Yes, that's something to be aware of. I use the approach on types which
are immutable, so it doesn't arise.
> size_t Derived::hash_value() const
> size_t seed = my_unique_value;
> hash_combine( seed, Base::hash_value() );
> hash_combine( seed, m_value );
> return seed;
That leaves the problem of assigning a different my_unique_value to each
subclass, bearing in mind that different subclasses may be written by
different people, teams or organisations. Without some kind of system
people may just copy and paste code from one class to another and not
change the value.
-- Dave Harris, Nottingham, UK
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk