From edf5c731fde69e4d509065cc6b236e973ef29c38 Mon Sep 17 00:00:00 2001 From: Orvid King Date: Tue, 13 Oct 2015 15:26:52 -0700 Subject: [PATCH] Handle less_than_impl and greater_than_impl under MSVC 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 | 66 ++++++++------------------------------------------ 1 file changed, 10 insertions(+), 56 deletions(-) diff --git a/folly/Traits.h b/folly/Traits.h index 0a291024..9701aa15 100644 --- a/folly/Traits.h +++ b/folly/Traits.h @@ -320,67 +320,21 @@ struct is_negative_impl { #pragma GCC diagnostic ignored "-Wsign-compare" template -bool less_than_impl( - typename std::enable_if< - (rhs <= std::numeric_limits::max() - && rhs > std::numeric_limits::min()), - LHS - >::type const lhs -) { - return lhs < rhs; -} - -template -bool less_than_impl( - typename std::enable_if< - (rhs > std::numeric_limits::max()), - LHS - >::type const -) { - return true; -} - -template -bool less_than_impl( - typename std::enable_if< - (rhs <= std::numeric_limits::min()), - LHS - >::type const -) { - return false; +bool less_than_impl(LHS const lhs) { + return + rhs > std::numeric_limits::max() ? true : + rhs <= std::numeric_limits::min() ? false : + lhs < rhs; } #pragma GCC diagnostic pop template -bool greater_than_impl( - typename std::enable_if< - (rhs <= std::numeric_limits::max() - && rhs >= std::numeric_limits::min()), - LHS - >::type const lhs -) { - return lhs > rhs; -} - -template -bool greater_than_impl( - typename std::enable_if< - (rhs > std::numeric_limits::max()), - LHS - >::type const -) { - return false; -} - -template -bool greater_than_impl( - typename std::enable_if< - (rhs < std::numeric_limits::min()), - LHS - >::type const -) { - return true; +bool greater_than_impl(LHS const lhs) { + return + rhs > std::numeric_limits::max() ? false : + rhs < std::numeric_limits::min() ? true : + lhs > rhs; } } // namespace detail { -- 2.34.1