mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-22 15:31:05 +01:00
[iter] Implement hb_reduce
This commit is contained in:
1 parent
f3aca6aa26
commit
e526414c75
2 files changed
+33
No files matched your search
@@ -348,6 +348,34 @@ static const struct
|
||||
{ return hb_filter_iter_factory_t<Pred, Proj> (p, f); }
|
||||
} hb_filter HB_UNUSED;
|
||||
|
||||
template <typename Redu, typename TValue>
|
||||
struct hb_reduce_t
|
||||
{
|
||||
hb_reduce_t (Redu r, TValue init_value) : r (r), init_value (init_value) {}
|
||||
|
||||
template <typename Iter,
|
||||
hb_enable_if (hb_is_iterator (Iter))>
|
||||
TValue
|
||||
operator () (Iter it) const
|
||||
{
|
||||
TValue value = init_value;
|
||||
for (; it; ++it)
|
||||
value = r (*it, value);
|
||||
return value;
|
||||
}
|
||||
|
||||
private:
|
||||
Redu r;
|
||||
TValue init_value;
|
||||
};
|
||||
static const struct
|
||||
{
|
||||
template <typename Redu, typename TValue> hb_reduce_t<Redu, TValue>
|
||||
operator () (Redu&& r, TValue init_value) const
|
||||
{ return hb_reduce_t<Redu, TValue> (r, init_value); }
|
||||
} hb_reduce HB_UNUSED;
|
||||
|
||||
|
||||
/* hb_zip() */
|
||||
|
||||
template <typename A, typename B>
|
||||
|
||||
@@ -154,6 +154,11 @@ main (int argc, char **argv)
|
||||
| hb_apply (&st)
|
||||
;
|
||||
|
||||
+ hb_iter (src)
|
||||
| hb_map ([&] (int i) -> int { return 1; })
|
||||
| hb_reduce ([&] (int acc, int cur) -> int { return acc + cur; }, 2)
|
||||
;
|
||||
|
||||
+ hb_iter (src)
|
||||
| hb_drain
|
||||
;
|
||||
|
||||
Reference in new issue
Block a user