[iter] Add hb_unzip()
This commit is contained in:
parent
f1dad91eb3
commit
6237b47f0c
|
@ -478,6 +478,8 @@ static const struct
|
||||||
{ return hb_sink_t<Sink&> (*s); }
|
{ return hb_sink_t<Sink&> (*s); }
|
||||||
} hb_sink HB_UNUSED;
|
} hb_sink HB_UNUSED;
|
||||||
|
|
||||||
|
/* hb-drain: hb_sink to void / blackhole / /dev/null. */
|
||||||
|
|
||||||
static const struct
|
static const struct
|
||||||
{
|
{
|
||||||
template <typename Iter,
|
template <typename Iter,
|
||||||
|
@ -490,6 +492,42 @@ static const struct
|
||||||
}
|
}
|
||||||
} hb_drain HB_UNUSED;
|
} hb_drain HB_UNUSED;
|
||||||
|
|
||||||
|
/* hb_unzip(): unzip and sink to two sinks. */
|
||||||
|
|
||||||
|
template <typename Sink1, typename Sink2>
|
||||||
|
struct hb_unzip_t
|
||||||
|
{
|
||||||
|
hb_unzip_t (Sink1&& s1, Sink2&& s2) : s1 (s1), s2 (s2) {}
|
||||||
|
|
||||||
|
template <typename Iter,
|
||||||
|
hb_enable_if (hb_is_iterator (Iter))>
|
||||||
|
void
|
||||||
|
operator () (Iter it) const
|
||||||
|
{
|
||||||
|
for (; it; ++it)
|
||||||
|
{
|
||||||
|
const auto &v = *it;
|
||||||
|
s1 << v.first;
|
||||||
|
s2 << v.second;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
Sink1 s1;
|
||||||
|
Sink2 s2;
|
||||||
|
};
|
||||||
|
static const struct
|
||||||
|
{
|
||||||
|
template <typename Sink1, typename Sink2> hb_unzip_t<Sink1, Sink2>
|
||||||
|
operator () (Sink1&& s1, Sink2&& s2) const
|
||||||
|
{ return hb_unzip_t<Sink1, Sink2> (s1, s2); }
|
||||||
|
|
||||||
|
template <typename Sink1, typename Sink2> hb_unzip_t<Sink1&, Sink2&>
|
||||||
|
operator () (Sink1 *s1, Sink2 *s2) const
|
||||||
|
{ return hb_unzip_t<Sink1&, Sink2&> (*s1, *s2); }
|
||||||
|
} hb_unzip HB_UNUSED;
|
||||||
|
|
||||||
|
|
||||||
/* hb-all, hb-any, hb-none. */
|
/* hb-all, hb-any, hb-none. */
|
||||||
|
|
||||||
static const struct
|
static const struct
|
||||||
|
|
Loading…
Reference in New Issue