转自 unordered_map的哈希HASH重载——举例unordered_map与pair联合使用_既然弱小,就只顾变强就是了-CSDN博客
如果使用
unordered_map< pair<int, int>, int > mp;
会报错
error: call to implicitly-deleted default constructor of 'std::__1::hash<std::__1::pair<int, int> >'
: _Hash() {}
这是因为pair还没有HASH键值。
改正需要:
struct hashfunc
{
template<typename T, typename U>
size_t operator() (const pair<T, U> &i) const
{
return hash<T>()(i.first) ^ hash<U>()(i.second);
}
};
unordered_map< pair<int, int>, int , hashfunc > mp;
原文链接: https://www.cnblogs.com/nntzhc/p/14347624.html
欢迎关注
微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍
原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/207864
非原创文章文中已经注明原地址,如有侵权,联系删除
关注公众号【高性能架构探索】,第一时间获取最新文章
转载文章受原作者版权保护。转载请注明原作者出处!