unordered_map用法

typedef pair<int, int> PII;
unordered_map<PII, int> a;
unordered_map<int, PII> b;

这样是错误的吗

键值对的数据类型可以是什么呀

这样是正确的
数据类型可以填int, long, short, long long, string, char, pair, unordered_map/set,set/map, vector等等

实现两个特化的模板类

using PII = pair<int, int>;
template<>
struct hash<PII> {
public:
    size_t operator()(const PII& p) const
    {
        return hash<int>()(p.first);
    }

};

template<>
struct equal_to<PII> {
public:
    bool operator()(const PII& p1, const PII& p2) const
    {
        return p1.first == p2.first && p1.second == p2.second;
    }

};


int main() {
    unordered_map<PII, int> a;
    unordered_map<int, PII> b;
    return 0;
}