mardi 19 novembre 2019

How to define a custom key equivalence predicate for an std::unordered_set?

I'm trying to define a key equivalence predicate for a hash set I'm using, but the compiler keeps telling me that function template "UniqueTable::table_key_equiv_pred" is not a type name and I don't understand why.

I've defined my equivalence function as this:

template<class t>
bool UniqueTable::table_key_equiv_pred(t a, node b) const
{
    return a == b;
}

template<>
bool UniqueTable::table_key_equiv_pred<int>(int a, node b) const
{
    return b && a == b->level;
}

template<>
bool UniqueTable::table_key_equiv_pred<node>(node a, node b) const
{
    return b && a && a->level == b->level && a->one == b->one && a->zero == b->zero;
}

And then instantiating a set using:

auto hashtable = new std::unordered_set<node, std::hash<node>, table_key_equiv_pred>();

How do I define a predicate to be used as a type parameter to an std::unordered_set?

Aucun commentaire:

Enregistrer un commentaire