[map] Use hb_invoke() with pointer-to-method

This commit is contained in:
Behdad Esfahbod 2019-04-24 10:43:40 -04:00
parent 8f79a5750e
commit 0268db1196
3 changed files with 14 additions and 3 deletions

View File

@ -73,7 +73,7 @@ struct
/* Pointer-to-member-function. */
template <typename Appl, typename Val1, typename ...Vals> auto
impl (Appl&& a, hb_priority<2>, Val1 &&v1, Vals &&...vs) const HB_AUTO_RETURN
(hb_deref_pointer (hb_forward<Val1> (v1)).*hb_forward<Appl> (a) (hb_forward<Vals> (vs)...))
((hb_deref_pointer (hb_forward<Val1> (v1)).*hb_forward<Appl> (a)) (hb_forward<Vals> (vs)...))
/* Pointer-to-member. */
template <typename Appl, typename Val> auto
@ -86,6 +86,9 @@ struct
(hb_deref_pointer (hb_forward<Appl> (a)) (hb_forward<Vals> (vs)...))
public:
template <typename Appl, typename Val1, typename ...Vals> auto
impl2 (Appl&& a, hb_priority<2>, Val1 &&v1, Vals &&...vs) const HB_AUTO_RETURN
(hb_deref_pointer (hb_forward<Val1> (v1)).*hb_forward<Appl> (a) (hb_forward<Vals> (vs)...))
template <typename Appl, typename ...Vals> auto
operator () (Appl&& a, Vals &&...vs) const HB_AUTO_RETURN

View File

@ -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;

View File

@ -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;
}