From fe30fcd228ff95be1f169f580b30184c8511d1c3 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 16 Apr 2019 17:34:06 -0400 Subject: [PATCH] Use hb_deref_pointer() to reduce number of overloads --- src/hb-algs.hh | 27 ++++++++++----------------- src/hb-meta.hh | 36 +++++++++++++++++++----------------- 2 files changed, 29 insertions(+), 34 deletions(-) diff --git a/src/hb-algs.hh b/src/hb-algs.hh index c21d8634e..6b80a61f9 100644 --- a/src/hb-algs.hh +++ b/src/hb-algs.hh @@ -72,21 +72,18 @@ struct /* Pointer-to-member-function. */ template auto - impl (Appl&& a, Val &&v, hb_priority<5>) const HB_AUTO_RETURN_EXPR (hb_forward (v).*a ()) - template auto - impl (Appl&& a, Val &&v, hb_priority<4>) const HB_AUTO_RETURN_EXPR (hb_forward (v)->*a ()) + impl (Appl&& a, Val &&v, hb_priority<2>) const HB_AUTO_RETURN_EXPR + (hb_forward (hb_deref_pointer (v)).*a ()) /* Pointer-to-member. */ template auto - impl (Appl&& a, Val &&v, hb_priority<3>) const HB_AUTO_RETURN_EXPR (hb_forward (v).*a) - template auto - impl (Appl&& a, Val &&v, hb_priority<2>) const HB_AUTO_RETURN_EXPR (hb_forward (v)->*a) + impl (Appl&& a, Val &&v, hb_priority<1>) const HB_AUTO_RETURN_EXPR + (hb_forward (hb_deref_pointer (v)).*a) /* Operator(). */ template auto - impl (Appl&& a, Val &&v, hb_priority<1>) const HB_AUTO_RETURN_EXPR (a (hb_forward (v))) - template auto - impl (Appl&& a, Val &&v, hb_priority<0>) const HB_AUTO_RETURN_EXPR ((*a) (hb_forward (v))) + impl (Appl&& a, Val &&v, hb_priority<0>) const HB_AUTO_RETURN_EXPR + (hb_deref_pointer (a) (hb_forward (v))) public: @@ -104,10 +101,8 @@ struct private: template auto - impl (Pred&& p, Val &&v, hb_priority<2>) const HB_AUTO_RETURN_EXPR (p->has (v)) - - template auto - impl (Pred&& p, Val &&v, hb_priority<1>) const HB_AUTO_RETURN_EXPR (p.has (v)) + impl (Pred&& p, Val &&v, hb_priority<1>) const HB_AUTO_RETURN_EXPR + (hb_deref_pointer (p).has (v)) template auto impl (Pred&& p, Val &&v, hb_priority<0>) const HB_AUTO_RETURN_EXPR @@ -132,10 +127,8 @@ struct private: template auto - impl (Proj&& f, Val &&v, hb_priority<2>) const HB_AUTO_RETURN_EXPR (f->get (hb_forward (v))) - - template auto - impl (Proj&& f, Val &&v, hb_priority<1>) const HB_AUTO_RETURN_EXPR (f.get (hb_forward (v))) + impl (Proj&& f, Val &&v, hb_priority<1>) const HB_AUTO_RETURN_EXPR + (hb_deref_pointer (f).get (hb_forward (v))) template auto impl (Proj&& f, Val &&v, hb_priority<0>) const HB_AUTO_RETURN_EXPR diff --git a/src/hb-meta.hh b/src/hb-meta.hh index a5edd0372..5698250fc 100644 --- a/src/hb-meta.hh +++ b/src/hb-meta.hh @@ -34,6 +34,15 @@ * C++ template meta-programming & fundamentals used with them. */ +/* Function overloading SFINAE and priority. */ + +#define HB_AUTO_RETURN_EXPR(E) -> decltype ((E)) { return (E); } +#define HB_VOID_RETURN_EXPR(E) -> hb_void_tt { (E); } + +template struct hb_priority : hb_priority {}; +template <> struct hb_priority<0> {}; +#define hb_prioritize hb_priority<16> () + #define HB_FUNCOBJ(x) static_const x HB_UNUSED struct @@ -67,14 +76,6 @@ template struct hb_match_pointer { typedef T type; enum { valu template using hb_remove_pointer = typename hb_match_pointer::type; #define hb_is_pointer(T) hb_match_pointer::value -struct -{ - template - T operator () (T v) const { return v; } - template - T& operator () (T *v) const { return *v; } -} HB_FUNCOBJ (hb_deref_pointer); - /* std::move and std::forward */ @@ -86,6 +87,16 @@ static T&& hb_forward (hb_remove_reference& t) { return (T&&) t; } template static T&& hb_forward (hb_remove_reference&& t) { return (T&&) t; } +struct +{ + template auto + operator () (T&& v) const HB_AUTO_RETURN_EXPR (hb_forward (v)) + + template auto + operator () (T *v) const HB_AUTO_RETURN_EXPR (*v) + +} HB_FUNCOBJ (hb_deref_pointer); + /* Void! For when we need a expression-type of void. */ struct hb_void_t { typedef void value; }; @@ -140,14 +151,5 @@ template <> struct hb_is_integer { enum { value = true }; }; template <> struct hb_is_integer { enum { value = true }; }; #define hb_is_integer(T) hb_is_integer::value -/* Function overloading SFINAE and priority. */ - -#define HB_AUTO_RETURN_EXPR(E) -> decltype ((E)) { return (E); } -#define HB_VOID_RETURN_EXPR(E) -> hb_void_tt { (E); } - -template struct hb_priority : hb_priority {}; -template <> struct hb_priority<0> {}; -#define hb_prioritize hb_priority<16> () - #endif /* HB_META_HH */