I have a std::unordered_map
with keys of type std::pair<T*, T*>
(i.e., a pair of pointers).
The code base has the following hash functor defined:
struct pair_hash {
template<typename T>
std::size_t operator()(std::pair<T, T> const &p) {
return (std::hash<T>()(p.first) + 0x9e3779b9) ^ (std::hash<T>()(p.second) + 0x9e3779b9);
}
};
And is used as:
std::unordered_map<std::pair<T*, T*>, U, pair_hash> myDictionary;
where U
is an arbitrary object.
Now the hash functor displayed above must have certain issues because in VC++ it gives me an out of bounds crash in std::unordered_map::find
.
Q:
- Could it be that my hash functor is problematic or this behaviour is attributed to VC++ itself?
- Is there a "proper/more proper" way to hash a pair of pointers?