From 6cd96ba1aca99b6eb31f8402d02c565dd4e96e03 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 30 Dec 2018 20:51:31 -0500 Subject: [PATCH] [iter] Make is_random_access_iterator a constant We cannot rely on constexpr functions... --- src/hb-array.hh | 2 +- src/hb-iter.hh | 11 ++++------- src/test-iter.cc | 2 +- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/hb-array.hh b/src/hb-array.hh index c800dda96..ff93e1153 100644 --- a/src/hb-array.hh +++ b/src/hb-array.hh @@ -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. */ diff --git a/src/hb-iter.hh b/src/hb-iter.hh index d00619840..93f79ef88 100644 --- a/src/hb-iter.hh +++ b/src/hb-iter.hh @@ -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) {} diff --git a/src/test-iter.cc b/src/test-iter.cc index b4f056b0c..8b66737e1 100644 --- a/src/test-iter.cc +++ b/src/test-iter.cc @@ -40,11 +40,11 @@ struct array_iter_t : array_iter_t (hb_array_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 arr;