[iter] Make is_random_access_iterator a constant
We cannot rely on constexpr functions...
This commit is contained in:
parent
a685bfe8fc
commit
6cd96ba1ac
|
@ -53,6 +53,7 @@ struct hb_array_t :
|
|||
* Iterator implementation.
|
||||
*/
|
||||
typedef Type& __item_type__;
|
||||
enum { is_random_access_iterator = true };
|
||||
Type& __item_at__ (unsigned i) const
|
||||
{
|
||||
if (unlikely (i >= length)) return CrapOrNull (Type);
|
||||
|
@ -72,7 +73,6 @@ struct hb_array_t :
|
|||
length -= n;
|
||||
}
|
||||
unsigned __len__ () const { return length; }
|
||||
bool __random_access__ () const { return true; }
|
||||
|
||||
/* Extra operators.
|
||||
*/
|
||||
|
|
|
@ -55,7 +55,8 @@ struct hb_iter_t
|
|||
typedef Iter iter_t;
|
||||
typedef Item item_t;
|
||||
enum { item_size = hb_static_size (Item) };
|
||||
enum { is_iter = true };
|
||||
enum { is_iterator = true };
|
||||
enum { is_random_access_iterator = false };
|
||||
|
||||
private:
|
||||
/* https://en.wikipedia.org/wiki/Curiously_recurring_template_pattern */
|
||||
|
@ -80,7 +81,6 @@ struct hb_iter_t
|
|||
iter_t operator ++ (int) { iter_t c (*thiz()); ++*thiz(); return c; }
|
||||
iter_t operator - (unsigned count) const { iter_t c (*thiz()); c -= count; return c; }
|
||||
iter_t operator -- (int) { iter_t c (*thiz()); --*thiz(); return c; }
|
||||
constexpr bool is_random_access () const { return thiz()->__random_access__ (); }
|
||||
|
||||
protected:
|
||||
hb_iter_t () {}
|
||||
|
@ -92,7 +92,8 @@ struct hb_iter_t
|
|||
using typename Name::iter_t; \
|
||||
using typename Name::item_t; \
|
||||
using Name::item_size; \
|
||||
using Name::is_iter; \
|
||||
using Name::is_iterator; \
|
||||
using Name::is_random_access_iterator; \
|
||||
using Name::iter; \
|
||||
using Name::operator bool; \
|
||||
using Name::len; \
|
||||
|
@ -105,7 +106,6 @@ struct hb_iter_t
|
|||
using Name::operator --; \
|
||||
using Name::operator +; \
|
||||
using Name::operator -; \
|
||||
using Name::is_random_access; \
|
||||
static_assert (true, "")
|
||||
|
||||
/* Base class for sorted iterators. Does not enforce anything.
|
||||
|
@ -146,9 +146,6 @@ struct hb_iter_mixin_t
|
|||
void __prev__ () { *thiz() -= 1; }
|
||||
void __rewind__ (unsigned n) { while (n--) --*thiz(); }
|
||||
|
||||
/* Random access: Implement if __item_at__(), __len__(), __forward__() are. */
|
||||
constexpr bool __random_access__ () const { return false; }
|
||||
|
||||
protected:
|
||||
hb_iter_mixin_t () {}
|
||||
hb_iter_mixin_t (const hb_iter_mixin_t &o HB_UNUSED) {}
|
||||
|
|
|
@ -40,11 +40,11 @@ struct array_iter_t :
|
|||
array_iter_t (hb_array_t<T> arr_) : arr (arr_) {}
|
||||
|
||||
typedef T& __item_type__;
|
||||
enum { is_random_access_iterator = true };
|
||||
T& __item_at__ (unsigned i) const { return arr[i]; }
|
||||
void __forward__ (unsigned n) { arr += n; }
|
||||
void __rewind__ (unsigned n) { arr -= n; }
|
||||
unsigned __len__ () const { return arr.length; }
|
||||
bool __random_access__ () const { return true; }
|
||||
|
||||
private:
|
||||
hb_array_t<T> arr;
|
||||
|
|
Loading…
Reference in New Issue