From 0268db11965d022883d5ef2ef828c0635165b7bd Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 24 Apr 2019 10:43:40 -0400 Subject: [PATCH] [map] Use hb_invoke() with pointer-to-method --- src/hb-algs.hh | 5 ++++- src/hb-map.hh | 4 ++-- src/test-algs.cc | 8 ++++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/hb-algs.hh b/src/hb-algs.hh index 3f627c108..c3467800b 100644 --- a/src/hb-algs.hh +++ b/src/hb-algs.hh @@ -73,7 +73,7 @@ struct /* Pointer-to-member-function. */ template auto impl (Appl&& a, hb_priority<2>, Val1 &&v1, Vals &&...vs) const HB_AUTO_RETURN - (hb_deref_pointer (hb_forward (v1)).*hb_forward (a) (hb_forward (vs)...)) + ((hb_deref_pointer (hb_forward (v1)).*hb_forward (a)) (hb_forward (vs)...)) /* Pointer-to-member. */ template auto @@ -86,6 +86,9 @@ struct (hb_deref_pointer (hb_forward (a)) (hb_forward (vs)...)) public: + template auto + impl2 (Appl&& a, hb_priority<2>, Val1 &&v1, Vals &&...vs) const HB_AUTO_RETURN + (hb_deref_pointer (hb_forward (v1)).*hb_forward (a) (hb_forward (vs)...)) template auto operator () (Appl&& a, Vals &&...vs) const HB_AUTO_RETURN diff --git a/src/hb-map.hh b/src/hb-map.hh index b99fb8f4b..9ffa83a8a 100644 --- a/src/hb-map.hh +++ b/src/hb-map.hh @@ -122,7 +122,7 @@ struct hb_hashmap_t return false; } + hb_iter (new_items, new_size) - | hb_apply ([] (item_t &_) { _.clear (); }) /* TODO make pointer-to-methods invokable. */ + | hb_apply (&item_t::clear) ; unsigned int old_size = mask + 1; @@ -193,7 +193,7 @@ struct hb_hashmap_t return; if (items) + hb_iter (items, mask + 1) - | hb_apply ([] (item_t &_) { _.clear (); }) /* TODO make pointer-to-methods invokable. */ + | hb_apply (&item_t::clear) ; population = occupancy = 0; diff --git a/src/test-algs.cc b/src/test-algs.cc index 8ec93f009..163a79ad3 100644 --- a/src/test-algs.cc +++ b/src/test-algs.cc @@ -34,6 +34,11 @@ test_func (int a, char **b) return b ? b[a] : nullptr; } +struct A +{ + void a () {} +}; + int main (int argc, char **argv) { @@ -54,5 +59,8 @@ main (int argc, char **argv) hb_invoke (test_func, 0, nullptr); + A a; + hb_invoke (&A::a, a); + return 0; }