Boost logo

Boost Users :

Subject: Re: [Boost-users] unordered_map: user object as key
From: André Santee (andre.santee_at_[hidden])
Date: 2010-02-27 14:37:24


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_at_[hidden]>

> 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 mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>



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