Boost logo

Boost :

Subject: Re: [boost] hash_combine vs hash_value
From: Daniel James (dnljms_at_[hidden])
Date: 2011-03-26 06:11:36


On 26 March 2011 02:26, Scott McMurray <me22.ca+boost_at_[hidden]> wrote:
>
> With combine, you can also use a non-zero initial value, so Point(x,y)
> and BoundingBox(x,y) don't have the same hash, if you happen to mix
> types in your tables.

That's a good point, but since STL containers aren't polymorphic it's
usually not the case. The boost hash function should always match the
equality operator, so that would be appropriate for writing
'hash_value' if you have a polymorphic equality operator that always
returns false for comparing a Point and a BoundingBox.

If you're using the library to write a hash function for another
purpose, that isn't really something I considered when writing the
documentation. I probably wasn't clear enough that I saw the library
as fairly single minded. I think it can work well if you're careful.
The design of your hash library could make a more appropriate base.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk