From 06a44e2e537303ab8ed1fb761bf3885eb433a718 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 30 Dec 2018 18:42:14 -0500 Subject: [PATCH] [iter/meta] Match hb_is_iterator<> using SFINAE By specifying Item type, which is desirable. --- src/hb-iter.hh | 28 +++++++++++----------------- src/hb-open-type.hh | 2 +- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/src/hb-iter.hh b/src/hb-iter.hh index 57f481d..87a86b8 100644 --- a/src/hb-iter.hh +++ b/src/hb-iter.hh @@ -177,29 +177,23 @@ struct hb_is_iterable { enum { value = _hb_is_iterable::value }; } /* The following SFINAE fails to match template parameters to hb_iter_t<>. * As such, just check for member is_iter being there. */ -# if 0 -template char -_hb_is_iterator (T *) {}; +template char +_hb_is_iterator (...) {}; template int _hb_is_iterator (hb_iter_t *) {}; +template int +_hb_is_iterator (hb_iter_t *) {}; +template int +_hb_is_iterator (hb_iter_t *) {}; +template int +_hb_is_iterator (hb_iter_t *) {}; static_assert (sizeof (char) != sizeof (int), ""); -template +template struct hb_is_iterator { enum { - value = sizeof (int) == sizeof (_hb_is_iterator (hb_declval ())) + value = sizeof (int) == sizeof (_hb_is_iterator (hb_declval ())) }; }; -#endif - -template -struct _hb_is_iterator -{ enum { value = false }; }; -template -struct _hb_is_iterator > -{ enum { value = true }; }; - -template -struct hb_is_iterator { enum { value = _hb_is_iterator::value }; }; -#define hb_is_iterator(Iterator) hb_is_iterator::value +#define hb_is_iterator(Iter, Item) hb_is_iterator::value /* diff --git a/src/hb-open-type.hh b/src/hb-open-type.hh index a1e30d2..60986a8 100644 --- a/src/hb-open-type.hh +++ b/src/hb-open-type.hh @@ -553,7 +553,7 @@ struct ArrayOf return_trace (true); } template - hb_enable_if_t (hb_is_iterator (Iterator), + hb_enable_if_t (hb_is_iterator (Iterator, Type), bool) serialize (hb_serialize_context_t *c, Iterator items) { -- 2.7.4