Boost logo

Boost Users :

Subject: Re: [Boost-users] unordered_map: user object as key
From: Daniel James (dnljms_at_[hidden])
Date: 2010-02-27 14:33:35


On 27 February 2010 19:21, André Santee <andre.santee_at_[hidden]> wrote:
> I know it has probably been asked a million times here, but I couldn't find
> any example that I could use.
> I want to create an unordered_map whose key is an object that I made
> (vector2), what's the best way of implementing a hash function to it? Can I
> have an example?

You need to implement 'hash_value' so that Boost.Hash can hash your
custom type, take a look at the last example in:

http://www.boost.org/doc/html/unordered/hash_equality.html#unordered.hash_equality.custom_types

It's pretty much what you want. There's more info in the Boost.Hash
documentation:

http://www.boost.org/doc/html/hash/custom.html

Daniel


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net