[iter] Add bidirectionality
This commit is contained in:
parent
314d8698d0
commit
19d2b5013d
|
@ -58,16 +58,22 @@ struct hb_iter_t
|
||||||
item_type_t& operator [] (unsigned i) { return item (i); }
|
item_type_t& operator [] (unsigned i) { return item (i); }
|
||||||
type_t& operator += (unsigned count) { forward (count); return thiz(); }
|
type_t& operator += (unsigned count) { forward (count); return thiz(); }
|
||||||
type_t& operator ++ () { next (); return thiz(); }
|
type_t& operator ++ () { next (); return thiz(); }
|
||||||
|
type_t& operator -= (unsigned count) { rewind (count); return thiz(); }
|
||||||
|
type_t& operator -- () { prev (); return thiz(); }
|
||||||
type_t operator + (unsigned count) { type_t c (*thiz()); c += count; return c; }
|
type_t operator + (unsigned count) { type_t c (*thiz()); c += count; return c; }
|
||||||
type_t operator ++ (int) { type_t c (*thiz()); ++*this; return c; }
|
type_t operator ++ (int) { type_t c (*thiz()); ++*thiz(); return c; }
|
||||||
|
type_t operator - (unsigned count) { type_t c (*thiz()); c -= count; return c; }
|
||||||
|
type_t operator -- (int) { type_t c (*thiz()); --*thiz(); return c; }
|
||||||
|
|
||||||
/* Methods. */
|
/* Methods. */
|
||||||
type_t iter () const { return *thiz(); }
|
type_t iter () const { return *thiz(); }
|
||||||
item_type_t item () const { return thiz()->__item__ (); }
|
item_type_t item () const { return thiz()->__item__ (); }
|
||||||
item_type_t item (unsigned i) const { return thiz()->__item__ (i); }
|
item_type_t item (unsigned i) const { return thiz()->__item__ (i); }
|
||||||
bool more () const { return thiz()->__more__ (); }
|
bool more () const { return thiz()->__more__ (); }
|
||||||
void next () { thiz()->next (); }
|
void next () { thiz()->__next__ (); }
|
||||||
void forward (unsigned n) { thiz()->__forward__ (n); }
|
void forward (unsigned n) { thiz()->__forward__ (n); }
|
||||||
|
void prev () { thiz()->__prev__ (); }
|
||||||
|
void rewind (unsigned n) { thiz()->__rewind__ (n); }
|
||||||
unsigned len () const { return thiz()->__len__ (); }
|
unsigned len () const { return thiz()->__len__ (); }
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -89,6 +95,10 @@ struct hb_iter_t
|
||||||
void __next__ () { thiz()->forward (1); }
|
void __next__ () { thiz()->forward (1); }
|
||||||
void __forward__ (unsigned n) { while (n--) next (); }
|
void __forward__ (unsigned n) { while (n--) next (); }
|
||||||
|
|
||||||
|
/* Rewinding: Implement __prev__() or __rewind__() if bidirectional. */
|
||||||
|
void __prev__ () { thiz()->rewind (1); }
|
||||||
|
void __rewind__ (unsigned n) { while (n--) prev (); }
|
||||||
|
|
||||||
/* Population: Implement __len__() if known. */
|
/* Population: Implement __len__() if known. */
|
||||||
unsigned __len__ () const
|
unsigned __len__ () const
|
||||||
{ type_t c (*thiz()); unsigned l = 0; while (c) { c++; l++; }; return l; }
|
{ type_t c (*thiz()); unsigned l = 0; while (c) { c++; l++; }; return l; }
|
||||||
|
|
Loading…
Reference in New Issue