I am trying to create a unordered-map using a pair as a key. This is something new for me so I followed some tutorials and I wrote this:
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 wmain(int argc, wchar_t * argv[])
{
{...}
using Key = std::pair<DWORD, DWORDLONG>;
std::unordered_map<Key, USN, pair_hash> mymap;
std::pair<DWORD, DWORDLONG> mypair(dwVolSN, fileId);
mymap.insert({ mypair, usn });
std::unordered_map<Key, USN>::const_iterator got;
got = mymap.find(mypair); // HERE I GET THE ERROR
return 0
}
Try std::unordered_map<Key, USN,
pair_hash
>::const_iterator got;
or auto got = mymap.find(mypair);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With