[iter] Add .random_access()
This commit is contained in:
parent
20f14b4aa6
commit
3dbe1e364c
|
@ -75,6 +75,7 @@ struct hb_iter_t
|
|||
void prev () { thiz()->__prev__ (); }
|
||||
void rewind (unsigned n) { thiz()->__rewind__ (n); }
|
||||
unsigned len () const { return thiz()->__len__ (); }
|
||||
bool random_access () const { return thiz()->__random_access__ (); }
|
||||
|
||||
/*
|
||||
* Subclasses overrides:
|
||||
|
@ -99,6 +100,9 @@ struct hb_iter_t
|
|||
/* Population: Implement __len__() if known. */
|
||||
unsigned __len__ () const
|
||||
{ iter_t c (*thiz()); unsigned l = 0; while (c) { c++; l++; }; return l; }
|
||||
|
||||
/* Random access: Return true if len(), forward(), item_at() are fast. */
|
||||
bool __random_access__ () const { return false; }
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -39,6 +39,7 @@ struct array_iter_t : hb_iter_t<array_iter_t<T>, T>
|
|||
void __forward__ (unsigned n) { arr += n; }
|
||||
void __rewind__ (unsigned n) { arr -= n; }
|
||||
unsigned __len__ () const { return arr.len; }
|
||||
bool __random_access__ () const { return true; }
|
||||
|
||||
private:
|
||||
hb_array_t<T> arr;
|
||||
|
|
Loading…
Reference in New Issue