使用pair作为unordered_map的key
struct pair_hash { template<class T1, class T2> std::size_t operator() (const std::pair<T1, T2>& p) const { auto h1 = std::hash<T1>{}(p.first); auto h2 = std::hash<T2>{}(p.second); return h1 ^ h2; } }; int main() { unordered_map<pair<int, int>, int, pair_hash> table; table.emplace(make_pair(1, 1), 1); cout << table[make_pair(1, 1)]; return 0; }
参考链接:https://blog.csdn.net/jk_chen_acmer/article/details/98204845