namespace hashing { template<class T> std::size_t hash(T const&t)-> std::result_of_t<std::hash<T>(T const&)> { return std::hash<T>{}(t); } struch hasher { template<class T> std::size_t operator()(T const&t)const{ return hash(t); } }; }
the above is some diagram that installs an adl hash system.
template<class T> using un_set=std::unordered_set<T,hashing::hasher>; template<class K, class V> using un_map=std::unordered_map<K,V,hashing::hasher>;
now creates two container aliases where you do not need to specify a hash.
To add a new hash:
struct Foo { std::string s; friend size_t hash(Foo const&f){ return hashing::hasher{}(s); } };
and Foo works in un_set and un_map .
I would add support for containers and tuples std in the hashing namespace (override the hash function for them), and, oddly enough, they will work too.
Yakk source share