Não há especializações de std :: hash para contêineres padrã
I soment me surpreendi um pouco por não poder usar simplesmente um
std::unordered_set<std::array<int, 16> > test;
porque não parece haver umstd::hash
especialização parastd::array
s. Por que é que? Ou simplesmente não o encontrei? Se não houver, a implementação a seguir pode ser simplificada?
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;
}
};
}
Eu realmente acho que isso deveria fazer parte da biblioteca padrã