I just found myself a little bit surprised being unable to simply use a
std::unordered_set<std::array<int, 16> > test;
because there does not seem to be a std::hash
specialization for std::array
s. Why is that? Or did I simply not find it? If there is indeed none, can the following implementation attempt be simplified?
namespace std
{
template<typename T, size_t N>
struct hash<array<T, N> >
{
typedef array<T, N> argument_type;
typedef size_t result_type;
result_type operator()(const argument_type& a) const
{
hash<T> hasher;
result_type h = 0;
for (result_type i = 0; i < N; ++i)
{
h = h * 31 + hasher(a[i]);
}
return h;
}
};
}
I really feel this should somehow be part of the standard library.