我只是发现自己有点惊讶不能简单地使用
std::unordered_set<std::array<int, 16> > test;
因为似乎没有 s 的std::hash
专业化std::array
。这是为什么?还是我根本没找到?如果确实没有,是否可以简化以下实现尝试?
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;
}
};
}
我真的觉得这应该以某种方式成为标准库的一部分。