[array] Add chop()
Takes n, and returns iterator of iterators that contain up to n items each. Basically cuts the array into subarrays of size n. The last sub-array might contain fewer. Ideally this should become a generic iter tool, not array-specific, so we can use it in GPOS to chop a value matrix into rows and elements.
This commit is contained in:
parent
c72589f13f
commit
545fe9d9f0
|
@ -183,6 +183,20 @@ struct hb_array_t : hb_iter_with_fallback_t<hb_array_t<Type>, Type&>
|
|||
|
||||
hb_array_t truncate (unsigned length) const { return sub_array (0, length); }
|
||||
|
||||
auto chop (unsigned n) const -> decltype
|
||||
(
|
||||
+ hb_range (0u, 0u, n)
|
||||
| hb_map (hb_partial<1> (hb_add, *this))
|
||||
| hb_map (hb_partial<2> (&hb_array_t::truncate, n))
|
||||
)
|
||||
{
|
||||
return
|
||||
+ hb_range (0u, length, n)
|
||||
| hb_map (hb_partial<1> (hb_add, *this))
|
||||
| hb_map (hb_partial<2> (&hb_array_t::truncate, n))
|
||||
;
|
||||
}
|
||||
|
||||
template <typename T,
|
||||
unsigned P = sizeof (Type),
|
||||
hb_enable_if (P == 1)>
|
||||
|
|
Loading…
Reference in New Issue