Add std::hash specialization for IntrusivePtr

This commit is contained in:
Jon Siwek 2021-04-03 09:49:43 -07:00
parent cffc8fa13c
commit 583310f6dd

View file

@ -4,6 +4,7 @@
#include <type_traits> #include <type_traits>
#include <utility> #include <utility>
#include <functional>
namespace zeek { namespace zeek {
@ -292,3 +293,13 @@ auto operator!=(const zeek::IntrusivePtr<T>& x, const zeek::IntrusivePtr<U>& y)
} }
} // namespace zeek } // namespace zeek
// -- hashing ------------------------------------------------
namespace std {
template <class T> struct hash<zeek::IntrusivePtr<T>> {
// Hash of intrusive pointer is the same as hash of the raw pointer it holds.
size_t operator()(const zeek::IntrusivePtr<T>& v) const noexcept
{ return std::hash<T*>{}(v.get()); }
};
}