Boost logo

Boost Users :

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


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?

struct vector2
{
    vector2();
    vector2(const vector2 &v2);
    vector2(float fx, float fy);
    vector2 operator * (float num) const;
    vector2 operator * (const vector2& v2) const;
    vector2 operator / (float num) const;
    vector2 operator / (const vector2& v2) const;
    vector2 operator - (float num) const;
    vector2 operator - (const vector2& v2) const;
    vector2 operator + (float num) const;
    vector2 operator + (const vector2& v2) const;
    bool operator == (const vector2& v2) const;
    bool operator != (const vector2& v2) const;
    vector2& operator += (const vector2& v2);
    vector2& operator -= (const vector2& v2);
    vector2& operator *= (float f);
    vector2& operator /= (float f);
    float x,y;
};

boost::unordered_map<vector2, int> won't work.



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