I'm writing a class that has an unordered_set of its own type as a member.
Therefore I need to write a specialization for hash<Foo>
. This specialization needs to be defined after Foo is declared. But it seems to me as if I already need the specialization for hash<Foo>
before defining the member unordered_set<Foo>
. At least it doesn't compile and fails there. I tried a forward declaration of the hash template but couldn't get it working thereby either.
The relevant code snippet is:
class Foo {
public:
int i;
std::unordered_set<Foo> dummy;
Peer(std::unordered_set<Foo>);
};
namespace std {
template<> struct hash<Foo>
{
size_t operator()(const Foo& f) const
{
return hash<int>()(f.i);
}
};
}
Thanks in advance