Hello, how exactly do I add a hash function so that std::vector<char> can be used as keys in std::unordered_map, seeing as it already works fine for std::string?
Thank you.
> Would you consider it bad practice to specialize std::hash()? Like so:
This is what the IS says:
The behavior of a C++ program is undefined if it adds declarations or definitions to namespace std or to a namespace within namespace std unless otherwise specified. A program may add a template specialization for any standard library template to namespace std only if the declaration depends on a user-defined type and the specialization meets the standard library requirements for the original template and is not explicitly prohibited.
Clearly, a specialization namespace std { template<> std::hash< my_own_type > { /* ... */ }; }
is permitted.
But it is not clear to me if 'user-defined type' referred to above includes types like std::vector<char> or these would be treated as 'library defined types'
I avoid adding anything to the namespace std if I can possibly get the functionality I need without doing it; but that's just me, I suppose.