[iter] Use different SFINAE scheme to make MSVC happy

From Orvid King: TLDR; MSVC has some issues using sizeof(declval<T>()) for
SFINAE of templated types, so I just used SFINAE in a different context where
MSVC doesn't have the issue.
This commit is contained in:
Behdad Esfahbod 2019-04-03 14:18:19 -07:00
parent 2778df7972
commit d419a9a437
1 changed files with 11 additions and 8 deletions

View File

@ -202,15 +202,18 @@ struct hb_iter_with_fallback_t :
/* hb_is_iterable() */
template<typename T, typename B>
struct _hb_is_iterable
{ enum { value = false }; };
template<typename T>
struct _hb_is_iterable<T, hb_bool_tt<true || sizeof (hb_declval (T).iter ())> >
{ enum { value = true }; };
template <typename T>
struct hb_is_iterable
{
private:
template <typename U>
static auto test (int) -> decltype (hb_declval (U).iter (), hb_true_t ());
template <typename>
static hb_false_t test (...);
template<typename T>
struct hb_is_iterable { enum { value = _hb_is_iterable<T, hb_true_t>::value }; };
public:
enum { value = hb_is_same (decltype (test<T> (0)), hb_true_t) };
};
#define hb_is_iterable(Iterable) hb_is_iterable<Iterable>::value
/* TODO Add hb_is_iterable_of().