How to create an unordered_map with pair as key in C++
Dec 17, 2020
Step 1: Define Structure.
struct
hash_pair {
template
<class
T1, class
T2>
size_t
operator()(const
pair<T1, T2>& p) const
{
auto
hash1 = hash<T1>{}(p.first);
auto
hash2 = hash<T2>{}(p.second);
return
hash1 ^ hash2;
}
};
Step 2: Declare this way
unordered_map<pair<int, int>, bool, hash_pair> um;