[iter] Remove hb_sorted_iter_t

Not enforcing it using type hierarchy.
This commit is contained in:
Behdad Esfahbod 2019-01-02 16:20:40 -05:00
parent 255085bd59
commit b5d6fe1a45
4 changed files with 12 additions and 26 deletions

View File

@ -193,11 +193,13 @@ enum hb_bfind_not_found_t
template <typename Type>
struct hb_sorted_array_t :
hb_sorted_iter_t<hb_sorted_array_t<Type>, Type&>,
hb_iter_t<hb_sorted_array_t<Type>, Type&>,
hb_array_t<Type>
{
typedef hb_sorted_iter_t<hb_sorted_array_t<Type>, Type&> iter_base_t;
typedef hb_iter_t<hb_sorted_array_t<Type>, 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<Type> () {}
hb_sorted_array_t (const hb_array_t<Type> &o) : hb_array_t<Type> (o) {}

View File

@ -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 <typename Iter, typename Item = typename Iter::__item_type__>
struct hb_sorted_iter_t : hb_iter_t<Iter, Item>
{
protected:
hb_sorted_iter_t () {}
hb_sorted_iter_t (const hb_sorted_iter_t &o) : hb_iter_t<Iter, Item> (o) {}
void operator = (const hb_sorted_iter_t &o HB_UNUSED) {}
};
/* Mixin to fill in what the subclass doesn't provide. */
template <typename iter_t, typename item_t = typename iter_t::__item_type__>
struct hb_iter_mixin_t
@ -183,16 +172,9 @@ struct hb_is_iterator { enum {
value = sizeof (int) == sizeof (_hb_is_iterator (hb_declval<Iter*> ())) }; };
#define hb_is_iterator(Iter, Item) hb_is_iterator<Iter, Item>::value
template<typename Iter = void, typename Item = void> char _hb_is_sorted_iterator (...) {};
template<typename Iter, typename Item> int _hb_is_sorted_iterator (hb_sorted_iter_t<Iter, Item> *) {};
template<typename Iter, typename Item> int _hb_is_sorted_iterator (hb_sorted_iter_t<Iter, const Item> *) {};
template<typename Iter, typename Item> int _hb_is_sorted_iterator (hb_sorted_iter_t<Iter, Item&> *) {};
template<typename Iter, typename Item> int _hb_is_sorted_iterator (hb_sorted_iter_t<Iter, const Item&> *) {};
static_assert (sizeof (char) != sizeof (int), "");
template<typename Iter, typename Item>
struct hb_is_sorted_iterator { enum {
value = sizeof (int) == sizeof (_hb_is_sorted_iterator (hb_declval<Iter*> ())) }; };
#define hb_is_sorted_iterator(Iter, Item) hb_is_sorted_iterator<Iter, Item>::value
#define hb_is_sorted_iterator(Iter, Item) \
hb_is_iterator (Iter, Item) && \
Iter::is_sorted_iterator
/*
* Algorithms operating on iterators or iteratables.

View File

@ -1115,9 +1115,10 @@ struct Coverage
}
struct iter_t :
hb_sorted_iter_t<iter_t, const hb_pair_t<unsigned, hb_codepoint_t> >,
hb_iter_t<iter_t, const hb_pair_t<unsigned, hb_codepoint_t> >,
hb_iter_mixin_t<iter_t, const hb_pair_t<unsigned, hb_codepoint_t> >
{
enum { is_sorted_iterator = true };
iter_t (const Coverage &c_ = Null(Coverage))
{
memset (this, 0, sizeof (*this));

View File

@ -672,9 +672,10 @@ struct hb_set_t
* Iterator implementation.
*/
struct iter_t :
hb_sorted_iter_t<iter_t, hb_codepoint_t>,
hb_iter_t<iter_t, hb_codepoint_t>,
hb_iter_mixin_t<iter_t, hb_codepoint_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__ (); }