From b702a0cbf8abae4622a99adf3a3b6adda3d9f2c1 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 14 Feb 2019 10:39:58 -0800 Subject: [PATCH] [iter] Add hb_sink() --- src/hb-iter.hh | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/hb-iter.hh b/src/hb-iter.hh index 290e6af3e..c275b94a1 100644 --- a/src/hb-iter.hh +++ b/src/hb-iter.hh @@ -364,6 +364,31 @@ inline hb_zip_iter_t hb_zip (const A& a, const B &b) { return hb_zip_iter_t (a.iter (), b.iter ()); } +/* hb_sink() */ + +template +struct hb_sink_t +{ + hb_sink_t (Sink&& s) : s (s) {} + + template + void + operator () (const Iterable &c) const + { + for (auto it = c.iter (); it; ++it) + s << *it; + } + + private: + Sink s; +}; +template +inline hb_sink_t +hb_sink (Sink&& s) +{ return hb_sink_t (s); } + + /* * Algorithms operating on iterators.