[iter] Add hb_apply()

This commit is contained in:
Behdad Esfahbod 2019-02-14 11:40:22 -08:00
parent 5b725784e5
commit 773d75637c
2 changed files with 33 additions and 0 deletions

View File

@ -370,6 +370,36 @@ static const struct
{ return hb_zip_iter_t<hb_iter_t (A), hb_iter_t (B)> (a.iter (), b.iter ()); }
} hb_zip HB_UNUSED;
/* hb_apply() */
template <typename Appl>
struct hb_apply_t
{
hb_apply_t (Appl&& a) : a (a) {}
template <typename Iter,
hb_enable_if (hb_is_iterator (Iter))>
void
operator () (Iter it) const
{
for (; it; ++it)
a (*it);
}
private:
Appl a;
};
static const struct
{
template <typename Appl> hb_apply_t<Appl>
operator () (Appl&& a) const
{ return hb_apply_t<Appl> (a); }
template <typename Appl> hb_apply_t<Appl&>
operator () (Appl *a) const
{ return hb_apply_t<Appl&> (*a); }
} hb_apply HB_UNUSED;
/* hb_sink() */
template <typename Sink>

View File

@ -148,6 +148,9 @@ main (int argc, char **argv)
| hb_sink (st)
;
+ hb_iter (src)
| hb_apply (&st);
t << 1;
long vl;
s >> vl;