提交 4b7f4dbc 编写于 作者: B Behdad Esfahbod

Add hb_deref_pointer()

上级 e5306927
...@@ -34,6 +34,19 @@ ...@@ -34,6 +34,19 @@
static const struct 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, template <typename T,
hb_enable_if (hb_is_integer (T))> hb_enable_if (hb_is_integer (T))>
uint32_t operator () (T v) const uint32_t operator () (T v) const
...@@ -41,11 +54,6 @@ static const struct ...@@ -41,11 +54,6 @@ static const struct
/* Knuth's multiplicative method: */ /* Knuth's multiplicative method: */
return (uint32_t) v * 2654435761u; 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; } hb_hash HB_UNUSED;
static const struct static const struct
......
...@@ -63,6 +63,14 @@ template <typename T> struct hb_match_pointer<T *> { typedef T type; enum { valu ...@@ -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_remove_pointer(T) typename hb_match_pointer<T>::type
#define hb_is_pointer(T) hb_match_pointer<T>::value #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. */ /* Void! For when we need a expression-type of void. */
struct hb_void_t { typedef void value; }; struct hb_void_t { typedef void value; };
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册