dimanche 5 juillet 2020

Class with std::unordered_set of pointers of same class

I am trying to create a class that has contains an std::unordered_set of pointers to the same class but am unable to find a way to prepare the hash function before declaring the class.

struct hash
{
   inline std::size_t operator()(Vertex const * & other);
};

struct Vertex
{
    // ...
    double x, y, z;
    std::unordered_set<Vertex *, hash> touching;
};

inline std::size_t hash::operator()(Vertex * const & other) const
{
    return ((hash<double>()(other->x))>>1)^
            ((hash<double>()(other->y))   )^
            ((hash<double>()(other->z))<<1);
}



Aucun commentaire:

Enregistrer un commentaire