[iter] Make iota() accept invokable for increasing to next item
This commit is contained in:
parent
3bc86fb237
commit
1f88dae9f5
|
@ -656,21 +656,32 @@ HB_FUNCOBJ (hb_range);
|
||||||
|
|
||||||
template <typename T, typename S>
|
template <typename T, typename S>
|
||||||
struct hb_iota_iter_t :
|
struct hb_iota_iter_t :
|
||||||
hb_iter_t<hb_iota_iter_t<T, S>, T>
|
hb_iter_with_fallback_t<hb_iota_iter_t<T, S>, T>
|
||||||
{
|
{
|
||||||
hb_iota_iter_t (T start, S step) : v (start), step (step) {}
|
hb_iota_iter_t (T start, S step) : v (start), step (step) {}
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
template <typename S2 = S>
|
||||||
|
auto
|
||||||
|
inc (S s, hb_priority<1>)
|
||||||
|
-> hb_void_t<decltype (hb_invoke (hb_forward<S2> (s), hb_declval<T&> ()))>
|
||||||
|
{ v = hb_invoke (hb_forward<S2> (s), v); }
|
||||||
|
|
||||||
|
void
|
||||||
|
inc (S s, hb_priority<0>)
|
||||||
|
{ v += s; }
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
typedef T __item_t__;
|
typedef T __item_t__;
|
||||||
static constexpr bool is_random_access_iterator = true;
|
static constexpr bool is_random_access_iterator = true;
|
||||||
static constexpr bool is_sorted_iterator = true;
|
static constexpr bool is_sorted_iterator = true;
|
||||||
__item_t__ __item__ () const { return hb_ridentity (v); }
|
__item_t__ __item__ () const { return hb_ridentity (v); }
|
||||||
__item_t__ __item_at__ (unsigned j) const { return v + j * step; }
|
|
||||||
bool __more__ () const { return true; }
|
bool __more__ () const { return true; }
|
||||||
unsigned __len__ () const { return UINT_MAX; }
|
unsigned __len__ () const { return UINT_MAX; }
|
||||||
void __next__ () { v += step; }
|
void __next__ () { inc (step, hb_prioritize); }
|
||||||
void __forward__ (unsigned n) { v += n * step; }
|
|
||||||
void __prev__ () { v -= step; }
|
void __prev__ () { v -= step; }
|
||||||
void __rewind__ (unsigned n) { v -= n * step; }
|
|
||||||
hb_iota_iter_t __end__ () const { return *this; }
|
hb_iota_iter_t __end__ () const { return *this; }
|
||||||
bool operator != (const hb_iota_iter_t& o) const { return true; }
|
bool operator != (const hb_iota_iter_t& o) const { return true; }
|
||||||
|
|
||||||
|
|
|
@ -267,6 +267,7 @@ main (int argc, char **argv)
|
||||||
hb_iota ();
|
hb_iota ();
|
||||||
hb_iota (3);
|
hb_iota (3);
|
||||||
hb_iota (3, 2);
|
hb_iota (3, 2);
|
||||||
|
assert ((&vl) + 1 == *++hb_iota (&vl, hb_inc));
|
||||||
hb_range ();
|
hb_range ();
|
||||||
hb_repeat (7u);
|
hb_repeat (7u);
|
||||||
hb_repeat (nullptr);
|
hb_repeat (nullptr);
|
||||||
|
|
Loading…
Reference in New Issue