[iter] Use different SFINAE scheme to make MSVC happy
authorBehdad Esfahbod <behdad@behdad.org>
Wed, 3 Apr 2019 21:18:19 +0000 (14:18 -0700)
committerBehdad Esfahbod <behdad@behdad.org>
Wed, 3 Apr 2019 21:18:19 +0000 (14:18 -0700)
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.

src/hb-iter.hh

index f23904c..afb0382 100644 (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 { enum { value = _hb_is_iterable<T, hb_true_t>::value }; };
+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 (...);
+
+  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().