I'm looking to implement a hash function over a C++ std::unordered_set<char>
. I initially tried using boost::hash_range:
namespace std
{
template<> struct hash<unordered_set<char> >
size_t operator(const unordered_set<char> &s)(
{
return boost::hash_range(begin(s), end(s))
};
}
But then I realised that because the set is unordered, the iteration order isn't stable, and the hash function is thus wrong. What are some better options for me? I guess I could std::set
instead of std::unordered_set
, but using an ordered set just because it's easier to hash seems ... wrong.