Add hb_deref_pointer()

This commit is contained in:
Behdad Esfahbod 2019-03-30 13:48:32 -07:00
parent e530692799
commit 4b7f4dbc0c
2 changed files with 21 additions and 5 deletions

View File

@ -34,6 +34,19 @@
static const struct
{
/* Don't know how to set priority of following. Doesn't work right now. */
//template <typename T>
//uint32_t operator () (const T& v) const
//{ return hb_deref_pointer (v).hash (); }
/* Instead, the following ugly soution: */
template <typename T,
hb_enable_if (!hb_is_integer (hb_remove_reference (T)) && !hb_is_pointer (T))>
uint32_t operator () (T&& v) const { return v.hash (); }
template <typename T>
uint32_t operator () (const T *v) const
{ return hb_hash (v); }
template <typename T,
hb_enable_if (hb_is_integer (T))>
uint32_t operator () (T v) const
@ -41,11 +54,6 @@ static const struct
/* Knuth's multiplicative method: */
return (uint32_t) v * 2654435761u;
}
template <typename T>
uint32_t operator () (T *v) const { return hb_hash (*v); }
template <typename T,
hb_enable_if (!hb_is_integer (hb_remove_reference (T)) && !hb_is_pointer (T))>
uint32_t operator () (T&& v) const { return v.hash (); }
} hb_hash HB_UNUSED;
static const struct

View File

@ -63,6 +63,14 @@ template <typename T> struct hb_match_pointer<T *> { typedef T type; enum { valu
#define hb_remove_pointer(T) typename hb_match_pointer<T>::type
#define hb_is_pointer(T) hb_match_pointer<T>::value
static const struct
{
template <typename T>
T& operator () (T v) { return v; }
template <typename T>
T& operator () (T *v) { return *v; }
} hb_deref_pointer HB_UNUSED;
/* Void! For when we need a expression-type of void. */
struct hb_void_t { typedef void value; };