Handle less_than_impl and greater_than_impl under MSVC
authorOrvid King <blah38621@gmail.com>
Tue, 13 Oct 2015 22:26:52 +0000 (15:26 -0700)
committerfacebook-github-bot-1 <folly-bot@fb.com>
Tue, 13 Oct 2015 23:20:18 +0000 (16:20 -0700)
Summary: MSVC chokes on the template constraints of these functions, so use a single implementation that will be const-folded by the optimizer instead.
Closes https://github.com/facebook/folly/pull/281

Reviewed By: @yfeldblum

Differential Revision: D2419069

fb-gh-sync-id: c9ad3d135430f8265bbc90391b45d9295d6de362

folly/Traits.h

index 0a291024baf55b48421e579dc0633f6559f9b01b..9701aa1573cd42b31fc585c5594465d1de5e7ebb 100644 (file)
@@ -320,67 +320,21 @@ struct is_negative_impl<T, false> {
 #pragma GCC diagnostic ignored "-Wsign-compare"
 
 template <typename RHS, RHS rhs, typename LHS>
-bool less_than_impl(
-  typename std::enable_if<
-    (rhs <= std::numeric_limits<LHS>::max()
-      && rhs > std::numeric_limits<LHS>::min()),
-    LHS
-  >::type const lhs
-) {
-  return lhs < rhs;
-}
-
-template <typename RHS, RHS rhs, typename LHS>
-bool less_than_impl(
-  typename std::enable_if<
-    (rhs > std::numeric_limits<LHS>::max()),
-    LHS
-  >::type const
-) {
-  return true;
-}
-
-template <typename RHS, RHS rhs, typename LHS>
-bool less_than_impl(
-  typename std::enable_if<
-    (rhs <= std::numeric_limits<LHS>::min()),
-    LHS
-  >::type const
-) {
-  return false;
+bool less_than_impl(LHS const lhs) {
+  return
+    rhs > std::numeric_limits<LHS>::max() ? true :
+    rhs <= std::numeric_limits<LHS>::min() ? false :
+    lhs < rhs;
 }
 
 #pragma GCC diagnostic pop
 
 template <typename RHS, RHS rhs, typename LHS>
-bool greater_than_impl(
-  typename std::enable_if<
-    (rhs <= std::numeric_limits<LHS>::max()
-      && rhs >= std::numeric_limits<LHS>::min()),
-    LHS
-  >::type const lhs
-) {
-  return lhs > rhs;
-}
-
-template <typename RHS, RHS rhs, typename LHS>
-bool greater_than_impl(
-  typename std::enable_if<
-    (rhs > std::numeric_limits<LHS>::max()),
-    LHS
-  >::type const
-) {
-  return false;
-}
-
-template <typename RHS, RHS rhs, typename LHS>
-bool greater_than_impl(
-  typename std::enable_if<
-    (rhs < std::numeric_limits<LHS>::min()),
-    LHS
-  >::type const
-) {
-  return true;
+bool greater_than_impl(LHS const lhs) {
+  return
+    rhs > std::numeric_limits<LHS>::max() ? false :
+    rhs < std::numeric_limits<LHS>::min() ? true :
+    lhs > rhs;
 }
 
 } // namespace detail {