[hash] Adjust hash for shared_ptr, implement it for std::hash
This commit is contained in:
parent
e037325efb
commit
a089d91fda
|
@ -240,17 +240,17 @@ struct
|
||||||
private:
|
private:
|
||||||
|
|
||||||
template <typename T> constexpr auto
|
template <typename T> constexpr auto
|
||||||
impl (const T& v, hb_priority<2>) const HB_RETURN (uint32_t, hb_deref (v).hash ())
|
impl (const T& v, hb_priority<1>) const HB_RETURN (uint32_t, hb_deref (v).hash ())
|
||||||
|
|
||||||
template <typename T> constexpr auto
|
|
||||||
impl (const T& v, hb_priority<1>) const HB_RETURN (uint32_t, std::hash<hb_decay<decltype (hb_deref (v))>>{} (hb_deref (v)))
|
|
||||||
|
|
||||||
template <typename T> constexpr uint32_t
|
template <typename T> constexpr uint32_t
|
||||||
impl (const hb::shared_ptr<T>& v, hb_priority<0>) const
|
impl (const hb::shared_ptr<T>& v, hb_priority<1>) const
|
||||||
{
|
{
|
||||||
return (uint32_t) (intptr_t) v.get () * 2654435761u;
|
return (uint32_t) (intptr_t) v.get ()->hash ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T> constexpr auto
|
||||||
|
impl (const T& v, hb_priority<0>) const HB_RETURN (uint32_t, std::hash<hb_decay<decltype (hb_deref (v))>>{} (hb_deref (v)))
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
template <typename T> constexpr auto
|
template <typename T> constexpr auto
|
||||||
|
|
|
@ -88,8 +88,6 @@ struct shared_ptr
|
||||||
template<typename T> struct is_shared_ptr : std::false_type {};
|
template<typename T> struct is_shared_ptr : std::false_type {};
|
||||||
template<typename T> struct is_shared_ptr<shared_ptr<T>> : std::true_type {};
|
template<typename T> struct is_shared_ptr<shared_ptr<T>> : std::true_type {};
|
||||||
|
|
||||||
// TODO Implement hash<> and atomic<>
|
|
||||||
|
|
||||||
template <typename T,
|
template <typename T,
|
||||||
T * (*_get_empty) (void),
|
T * (*_get_empty) (void),
|
||||||
T * (*_reference) (T *),
|
T * (*_reference) (T *),
|
||||||
|
@ -135,6 +133,19 @@ HB_DEFINE_VTABLE (unicode_funcs);
|
||||||
|
|
||||||
} // namespace hb
|
} // namespace hb
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
struct std::hash<hb::shared_ptr<T>>
|
||||||
|
{
|
||||||
|
std::size_t operator()(const hb::shared_ptr<T>& v) const noexcept
|
||||||
|
{
|
||||||
|
std::size_t h = std::hash<decltype (v.get ())>{}(v.get ());
|
||||||
|
return h;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// TODO Implement atomic<>
|
||||||
|
|
||||||
|
|
||||||
#endif /* __cplusplus */
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
#endif /* HB_CPLUSPLUS_HH */
|
#endif /* HB_CPLUSPLUS_HH */
|
||||||
|
|
Loading…
Reference in New Issue