[iter] Add hb_apply()
This commit is contained in:
parent
5b725784e5
commit
773d75637c
|
@ -370,6 +370,36 @@ static const struct
|
||||||
{ return hb_zip_iter_t<hb_iter_t (A), hb_iter_t (B)> (a.iter (), b.iter ()); }
|
{ return hb_zip_iter_t<hb_iter_t (A), hb_iter_t (B)> (a.iter (), b.iter ()); }
|
||||||
} hb_zip HB_UNUSED;
|
} 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() */
|
/* hb_sink() */
|
||||||
|
|
||||||
template <typename Sink>
|
template <typename Sink>
|
||||||
|
|
|
@ -148,6 +148,9 @@ main (int argc, char **argv)
|
||||||
| hb_sink (st)
|
| hb_sink (st)
|
||||||
;
|
;
|
||||||
|
|
||||||
|
+ hb_iter (src)
|
||||||
|
| hb_apply (&st);
|
||||||
|
|
||||||
t << 1;
|
t << 1;
|
||||||
long vl;
|
long vl;
|
||||||
s >> vl;
|
s >> vl;
|
||||||
|
|
Loading…
Reference in New Issue