From b8e763fd7140b3e298863e04053ec0f3c73a6a70 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 16 Apr 2019 10:50:22 -0400 Subject: [PATCH] [meta] Add hb_invoke() --- src/hb-algs.hh | 34 ++++++++++++++++++++++++++++++++-- src/hb-iter.hh | 2 +- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/hb-algs.hh b/src/hb-algs.hh index 1cda64f9b..1460e72fb 100644 --- a/src/hb-algs.hh +++ b/src/hb-algs.hh @@ -70,6 +70,29 @@ struct operator () (const T& v) const { return bool (v); } } HB_FUNCOBJ (hb_bool); + +struct +{ + private: + + // TODO Add overload to for pointer-to-member-function + + 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))) + + public: + + template auto + operator () (Appl&& a, Val &&v) const HB_AUTO_RETURN_EXPR ( + impl (hb_forward (a), + hb_forward (v), + hb_prioritize) + ) +} HB_FUNCOBJ (hb_invoke); + struct { private: @@ -81,7 +104,10 @@ struct impl (Pred&& p, Val &&v, hb_priority<1>) const HB_AUTO_RETURN_EXPR (p.has (v)) template auto - impl (Pred&& p, Val &&v, hb_priority<0>) const HB_AUTO_RETURN_EXPR (p (v)) + impl (Pred&& p, Val &&v, hb_priority<0>) const HB_AUTO_RETURN_EXPR ( + hb_invoke (hb_forward (p), + hb_forward (v)) + ) public: @@ -104,7 +130,10 @@ struct impl (Proj&& f, Val &&v, hb_priority<1>) const HB_AUTO_RETURN_EXPR (f.get (hb_forward (v))) template auto - impl (Proj&& f, Val &&v, hb_priority<2>) const HB_AUTO_RETURN_EXPR (f (hb_forward (v))) + impl (Proj&& f, Val &&v, hb_priority<2>) const HB_AUTO_RETURN_EXPR ( + hb_invoke (hb_forward (f), + hb_forward (v)) + ) public: @@ -116,6 +145,7 @@ struct ) } HB_FUNCOBJ (hb_get); + template struct hb_pair_t { diff --git a/src/hb-iter.hh b/src/hb-iter.hh index 719987dea..7e7673326 100644 --- a/src/hb-iter.hh +++ b/src/hb-iter.hh @@ -471,7 +471,7 @@ struct hb_apply_t operator () (Iter it) const { for (; it; ++it) - a (*it); + (void) hb_invoke (a, *it); } private: