Fix for clang (llvm 3.7.0+)
author191919 <191919@gmail.com>
Tue, 23 Jun 2015 16:59:11 +0000 (09:59 -0700)
committerSara Golemon <sgolemon@fb.com>
Tue, 23 Jun 2015 18:24:17 +0000 (11:24 -0700)
Summary: Roughly described in https://github.com/facebook/hhvm/issues/5344.

Closes #206

Reviewed By: @yfeldblum

Differential Revision: D2170803

Pulled By: @sgolemon

folly/DynamicConverter.h
folly/test/DynamicConverterTest.cpp

index 16c3a0888bf7150e635231a4bddfc140a426193e..4c8b910cc466a3af4d03ccb40e455391c2ae1250 100644 (file)
@@ -54,13 +54,20 @@ BOOST_MPL_HAS_XXX_TRAIT_DEF(value_type);
 BOOST_MPL_HAS_XXX_TRAIT_DEF(iterator);
 BOOST_MPL_HAS_XXX_TRAIT_DEF(mapped_type);
 
-template <typename T> struct class_is_container {
-  typedef std::reverse_iterator<T*> some_iterator;
+template <typename T> struct iterator_class_is_container {
+  typedef std::reverse_iterator<typename T::iterator> some_iterator;
   enum { value = has_value_type<T>::value &&
-                 has_iterator<T>::value &&
               std::is_constructible<T, some_iterator, some_iterator>::value };
 };
 
+template <typename T>
+using class_is_container = typename
+  std::conditional<
+    has_iterator<T>::value,
+    iterator_class_is_container<T>,
+    std::false_type
+  >::type;
+
 template <typename T> struct class_is_range {
   enum { value = has_value_type<T>::value &&
                  has_iterator<T>::value };
index 63bfa02281d0c61e41f1e2e8c174fb6944b5d8d2..2e5003dedc6df79d412777de6a92a4fe5452a606 100644 (file)
@@ -35,17 +35,21 @@ TEST(DynamicConverter, template_metaprogramming) {
   bool c1f = is_container<int>::value;
   bool c2f = is_container<std::pair<int, int>>::value;
   bool c3f = is_container<A>::value;
+  bool c4f = class_is_container<A>::value;
 
   bool c1t = is_container<std::vector<int>>::value;
   bool c2t = is_container<std::set<int>>::value;
   bool c3t = is_container<std::map<int, int>>::value;
+  bool c4t = class_is_container<std::vector<A>>::value;
 
   EXPECT_EQ(c1f, false);
   EXPECT_EQ(c2f, false);
   EXPECT_EQ(c3f, false);
+  EXPECT_EQ(c4f, false);
   EXPECT_EQ(c1t, true);
   EXPECT_EQ(c2t, true);
   EXPECT_EQ(c3t, true);
+  EXPECT_EQ(c4t, true);
 
 
   bool m1f = is_map<int>::value;