From 773d75637c36426b96be43f1188c68d77ac4ba47 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 14 Feb 2019 11:40:22 -0800 Subject: [PATCH] [iter] Add hb_apply() --- src/hb-iter.hh | 30 ++++++++++++++++++++++++++++++ src/test-iter.cc | 3 +++ 2 files changed, 33 insertions(+) diff --git a/src/hb-iter.hh b/src/hb-iter.hh index 24a10f311..9f912b912 100644 --- a/src/hb-iter.hh +++ b/src/hb-iter.hh @@ -370,6 +370,36 @@ static const struct { return hb_zip_iter_t (a.iter (), b.iter ()); } } hb_zip HB_UNUSED; +/* hb_apply() */ + +template +struct hb_apply_t +{ + hb_apply_t (Appl&& a) : a (a) {} + + template + void + operator () (Iter it) const + { + for (; it; ++it) + a (*it); + } + + private: + Appl a; +}; +static const struct +{ + template hb_apply_t + operator () (Appl&& a) const + { return hb_apply_t (a); } + + template hb_apply_t + operator () (Appl *a) const + { return hb_apply_t (*a); } +} hb_apply HB_UNUSED; + /* hb_sink() */ template diff --git a/src/test-iter.cc b/src/test-iter.cc index ffd08bb83..a96616369 100644 --- a/src/test-iter.cc +++ b/src/test-iter.cc @@ -148,6 +148,9 @@ main (int argc, char **argv) | hb_sink (st) ; + + hb_iter (src) + | hb_apply (&st); + t << 1; long vl; s >> vl;