[iter/meta] Match hb_is_iterator<> using SFINAE

By specifying Item type, which is desirable.
This commit is contained in:
Behdad Esfahbod 2018-12-30 18:42:14 -05:00
parent bcb913efb4
commit 06a44e2e53
2 changed files with 12 additions and 18 deletions

View File

@ -177,29 +177,23 @@ struct hb_is_iterable { enum { value = _hb_is_iterable<T, hb_true_t>::value }; }
/* The following SFINAE fails to match template parameters to hb_iter_t<>. /* The following SFINAE fails to match template parameters to hb_iter_t<>.
* As such, just check for member is_iter being there. */ * As such, just check for member is_iter being there. */
# if 0 template<typename Iter = void, typename Item = void> char
template<typename T = void> char _hb_is_iterator (...) {};
_hb_is_iterator (T *) {};
template<typename Iter, typename Item> int template<typename Iter, typename Item> int
_hb_is_iterator (hb_iter_t<Iter, Item> *) {}; _hb_is_iterator (hb_iter_t<Iter, Item> *) {};
template<typename Iter, typename Item> int
_hb_is_iterator (hb_iter_t<Iter, const Item> *) {};
template<typename Iter, typename Item> int
_hb_is_iterator (hb_iter_t<Iter, Item&> *) {};
template<typename Iter, typename Item> int
_hb_is_iterator (hb_iter_t<Iter, const Item&> *) {};
static_assert (sizeof (char) != sizeof (int), ""); static_assert (sizeof (char) != sizeof (int), "");
template<typename T> template<typename Iter, typename Item>
struct hb_is_iterator { enum { struct hb_is_iterator { enum {
value = sizeof (int) == sizeof (_hb_is_iterator (hb_declval<T*> ())) value = sizeof (int) == sizeof (_hb_is_iterator (hb_declval<Iter*> ()))
}; }; }; };
#endif #define hb_is_iterator(Iter, Item) hb_is_iterator<Iter, Item>::value
template<typename T, typename B>
struct _hb_is_iterator
{ enum { value = false }; };
template<typename T>
struct _hb_is_iterator<T, hb_bool_tt<true || sizeof (T::is_iter)> >
{ enum { value = true }; };
template<typename T>
struct hb_is_iterator { enum { value = _hb_is_iterator<T, hb_true_t>::value }; };
#define hb_is_iterator(Iterator) hb_is_iterator<Iterator>::value
/* /*

View File

@ -553,7 +553,7 @@ struct ArrayOf
return_trace (true); return_trace (true);
} }
template <typename Iterator> template <typename Iterator>
hb_enable_if_t (hb_is_iterator (Iterator), hb_enable_if_t (hb_is_iterator (Iterator, Type),
bool) serialize (hb_serialize_context_t *c, bool) serialize (hb_serialize_context_t *c,
Iterator items) Iterator items)
{ {