Thanks,
I solved my problem by doing this:

namespace boost
{
    std::size_t hash_value(const GS_VECTOR2 &v2)
    {
        return ((std::size_t)v2.y*COLUMNS)+(std::size_t)v2.x;
    }
};

Is it also ok?

André.

2010/2/27 Daniel James <dnljms@gmail.com>
On 27 February 2010 19:21, André Santee <andre.santee@gmail.com> 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 mailing list
Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users