From ce4d63beec08995aaa6b8b45f7986f074a73f295 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 30 Aug 2019 11:59:50 -0500 Subject: [PATCH] [iter] Separate hb_iota implementation from hb_range --- src/hb-iter.hh | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/hb-iter.hh b/src/hb-iter.hh index b9d9f286a..3e0a2d9dc 100644 --- a/src/hb-iter.hh +++ b/src/hb-iter.hh @@ -654,11 +654,36 @@ struct } HB_FUNCOBJ (hb_range); +template +struct hb_iota_iter_t : + hb_iter_t, T> +{ + hb_iota_iter_t (T start, S step) : v (start), step (step) {} + + typedef T __item_t__; + static constexpr bool is_random_access_iterator = true; + static constexpr bool is_sorted_iterator = true; + __item_t__ __item__ () const { return +v; } + __item_t__ __item_at__ (unsigned j) const { return v + j * step; } + bool __more__ () const { return true; } + unsigned __len__ () const { return UINT_MAX; } + void __next__ () { v += step; } + void __forward__ (unsigned n) { v += n * step; } + void __prev__ () { v -= step; } + void __rewind__ (unsigned n) { v -= n * step; } + hb_iota_iter_t __end__ () const { return hb_iota_iter_t (v, step); } + bool operator != (const hb_iota_iter_t& o) const { return true; } + + private: + T v; + S step; +}; + struct { - template hb_range_iter_t + template hb_iota_iter_t operator () (T start = 0u, S&& step = 1u) const - { return hb_range_iter_t (start, step >= 0 ? hb_int_max (T) : hb_int_min (T), step); } + { return hb_iota_iter_t (start, step); } } HB_FUNCOBJ (hb_iota);