Commit 850b5469 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Let to_signed be constexpr under C++11 rules

Summary: [Folly] Let `to_signed` be `constexpr` under C++11 rules.

Reviewed By: simpkins

Differential Revision: D7079545

fbshipit-source-id: 69a56f2180f9ec3492cd1ad9cd26dd8bba255442
parent 7d455083
...@@ -371,8 +371,8 @@ constexpr auto to_signed(T const& t) -> typename std::make_signed<T>::type { ...@@ -371,8 +371,8 @@ constexpr auto to_signed(T const& t) -> typename std::make_signed<T>::type {
// note: static_cast<S>(t) would be more straightforward, but it would also be // note: static_cast<S>(t) would be more straightforward, but it would also be
// implementation-defined behavior and that is typically to be avoided; the // implementation-defined behavior and that is typically to be avoided; the
// following code optimized into the same thing, though // following code optimized into the same thing, though
constexpr auto const s = std::numeric_limits<S>::max(); return std::numeric_limits<S>::max() < t ? -static_cast<S>(~t) + S{-1}
return s < t ? -static_cast<S>(~t) + S{-1} : static_cast<S>(t); : static_cast<S>(t);
} }
template <typename T> template <typename T>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment