From b5d6fe1a452c72dd47d20c03a563321771330acc Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 2 Jan 2019 16:20:40 -0500 Subject: [PATCH] [iter] Remove hb_sorted_iter_t Not enforcing it using type hierarchy. --- src/hb-array.hh | 6 ++++-- src/hb-iter.hh | 26 ++++---------------------- src/hb-ot-layout-common.hh | 3 ++- src/hb-set.hh | 3 ++- 4 files changed, 12 insertions(+), 26 deletions(-) diff --git a/src/hb-array.hh b/src/hb-array.hh index ff93e1153..70053b4e7 100644 --- a/src/hb-array.hh +++ b/src/hb-array.hh @@ -193,11 +193,13 @@ enum hb_bfind_not_found_t template struct hb_sorted_array_t : - hb_sorted_iter_t, Type&>, + hb_iter_t, Type&>, hb_array_t { - typedef hb_sorted_iter_t, Type&> iter_base_t; + typedef hb_iter_t, Type&> iter_base_t; HB_ITER_USING (iter_base_t); + enum { is_random_access_iterator = true }; + enum { is_sorted_iterator = true }; hb_sorted_array_t () : hb_array_t () {} hb_sorted_array_t (const hb_array_t &o) : hb_array_t (o) {} diff --git a/src/hb-iter.hh b/src/hb-iter.hh index 8510ec009..4cdad76e8 100644 --- a/src/hb-iter.hh +++ b/src/hb-iter.hh @@ -57,6 +57,7 @@ struct hb_iter_t enum { item_size = hb_static_size (Item) }; enum { is_iterator = true }; enum { is_random_access_iterator = false }; + enum { is_sorted_iterator = false }; private: /* https://en.wikipedia.org/wiki/Curiously_recurring_template_pattern */ @@ -93,7 +94,6 @@ struct hb_iter_t using typename Name::item_t; \ using Name::item_size; \ using Name::is_iterator; \ - using Name::is_random_access_iterator; \ using Name::iter; \ using Name::operator bool; \ using Name::len; \ @@ -108,17 +108,6 @@ struct hb_iter_t using Name::operator -; \ static_assert (true, "") -/* Base class for sorted iterators. Does not enforce anything. - * Just for class taxonomy and requirements. */ -template -struct hb_sorted_iter_t : hb_iter_t -{ - protected: - hb_sorted_iter_t () {} - hb_sorted_iter_t (const hb_sorted_iter_t &o) : hb_iter_t (o) {} - void operator = (const hb_sorted_iter_t &o HB_UNUSED) {} -}; - /* Mixin to fill in what the subclass doesn't provide. */ template struct hb_iter_mixin_t @@ -183,16 +172,9 @@ struct hb_is_iterator { enum { value = sizeof (int) == sizeof (_hb_is_iterator (hb_declval ())) }; }; #define hb_is_iterator(Iter, Item) hb_is_iterator::value -template char _hb_is_sorted_iterator (...) {}; -template int _hb_is_sorted_iterator (hb_sorted_iter_t *) {}; -template int _hb_is_sorted_iterator (hb_sorted_iter_t *) {}; -template int _hb_is_sorted_iterator (hb_sorted_iter_t *) {}; -template int _hb_is_sorted_iterator (hb_sorted_iter_t *) {}; -static_assert (sizeof (char) != sizeof (int), ""); -template -struct hb_is_sorted_iterator { enum { - value = sizeof (int) == sizeof (_hb_is_sorted_iterator (hb_declval ())) }; }; -#define hb_is_sorted_iterator(Iter, Item) hb_is_sorted_iterator::value +#define hb_is_sorted_iterator(Iter, Item) \ + hb_is_iterator (Iter, Item) && \ + Iter::is_sorted_iterator /* * Algorithms operating on iterators or iteratables. diff --git a/src/hb-ot-layout-common.hh b/src/hb-ot-layout-common.hh index 921fb88c6..93dabf14a 100644 --- a/src/hb-ot-layout-common.hh +++ b/src/hb-ot-layout-common.hh @@ -1115,9 +1115,10 @@ struct Coverage } struct iter_t : - hb_sorted_iter_t >, + hb_iter_t >, hb_iter_mixin_t > { + enum { is_sorted_iterator = true }; iter_t (const Coverage &c_ = Null(Coverage)) { memset (this, 0, sizeof (*this)); diff --git a/src/hb-set.hh b/src/hb-set.hh index 1015741f5..ea27eb92c 100644 --- a/src/hb-set.hh +++ b/src/hb-set.hh @@ -672,9 +672,10 @@ struct hb_set_t * Iterator implementation. */ struct iter_t : - hb_sorted_iter_t, + hb_iter_t, hb_iter_mixin_t { + enum { is_sorted_iterator = true }; iter_t (const hb_set_t &s_ = Null(hb_set_t)) : s (&s_), v (INVALID), l (s->get_population () + 1) { __next__ (); }