Expression SFINAE issue in base.h
authorElizabeth Smith <elizabeths@fb.com>
Thu, 10 Jul 2014 21:54:28 +0000 (14:54 -0700)
committerTudor Bosman <tudorb@fb.com>
Mon, 14 Jul 2014 19:13:53 +0000 (12:13 -0700)
Summary:
MSVC 14 is still broken with expression sfinae - and the things that break are often strange
Moving this out into two expr templates solves the compilation issue

Test Plan: fbconfig -r folly && fbmake runtests

Reviewed By: tjackson@fb.com

FB internal diff: D1413297

folly/gen/Base.h

index 2c8c2635f32a5e265206b1dc4939bdb7f89e318b..bbae117a505ddb822d442e4cfb96e079b90a96b7 100644 (file)
@@ -537,12 +537,29 @@ enum MemberType {
   Mutable
 };
 
+/**
+ * These exist because MSVC has problems with expression SFINAE in templates
+ * assignment and comparisons don't work properly without being pulled out
+ * of the template declaration
+ */
+template <MemberType Constness> struct ExprIsConst {
+  enum {
+    value = Constness == Const
+  };
+};
+
+template <MemberType Constness> struct ExprIsMutable {
+  enum {
+    value = Constness == Mutable
+  };
+};
+
 template<MemberType Constness = Const,
          class Class,
          class Return,
          class Mem = ConstMemberFunction<Class, Return>,
          class Map = detail::Map<Mem>>
-typename std::enable_if<Constness == Const, Map>::type
+typename std::enable_if<ExprIsConst<Constness>::value, Map>::type
 member(Return (Class::*member)() const) {
   return Map(Mem(member));
 }
@@ -552,7 +569,7 @@ template<MemberType Constness = Mutable,
          class Return,
          class Mem = MemberFunction<Class, Return>,
          class Map = detail::Map<Mem>>
-typename std::enable_if<Constness == Mutable, Map>::type
+typename std::enable_if<ExprIsMutable<Constness>::value, Map>::type
 member(Return (Class::*member)()) {
   return Map(Mem(member));
 }