From 4b7f4dbc0cf58d87f4c91f059734e91e4d988480 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 30 Mar 2019 13:48:32 -0700 Subject: [PATCH] Add hb_deref_pointer() --- src/hb-algs.hh | 18 +++++++++++++----- src/hb-meta.hh | 8 ++++++++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/hb-algs.hh b/src/hb-algs.hh index 3eb01d8be..128e49036 100644 --- a/src/hb-algs.hh +++ b/src/hb-algs.hh @@ -34,6 +34,19 @@ static const struct { + /* Don't know how to set priority of following. Doesn't work right now. */ + //template + //uint32_t operator () (const T& v) const + //{ return hb_deref_pointer (v).hash (); } + /* Instead, the following ugly soution: */ + template + uint32_t operator () (T&& v) const { return v.hash (); } + + template + uint32_t operator () (const T *v) const + { return hb_hash (v); } + template uint32_t operator () (T v) const @@ -41,11 +54,6 @@ static const struct /* Knuth's multiplicative method: */ return (uint32_t) v * 2654435761u; } - template - uint32_t operator () (T *v) const { return hb_hash (*v); } - template - uint32_t operator () (T&& v) const { return v.hash (); } } hb_hash HB_UNUSED; static const struct diff --git a/src/hb-meta.hh b/src/hb-meta.hh index 6d9dd6b6c..ef139fad2 100644 --- a/src/hb-meta.hh +++ b/src/hb-meta.hh @@ -63,6 +63,14 @@ template struct hb_match_pointer { typedef T type; enum { valu #define hb_remove_pointer(T) typename hb_match_pointer::type #define hb_is_pointer(T) hb_match_pointer::value +static const struct +{ + template + T& operator () (T v) { return v; } + template + 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; };