Commit 375e7918 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook GitHub Bot

lift the sfinae from to_narrow_convertible::operator()

Summary: Having the complex conditions extracted to helper variables or types leaves the function declaration simpler.

Differential Revision: D33992433

fbshipit-source-id: f51775bc2901bb232c1bbd3136eb988e234c8af2
parent 95f1ce0f
......@@ -402,11 +402,21 @@ struct to_unsigned_fn {
};
FOLLY_INLINE_VARIABLE constexpr to_unsigned_fn to_unsigned{};
namespace detail {
template <typename Src, typename Dst>
FOLLY_INLINE_VARIABLE constexpr bool is_to_narrow_convertible_v =
(std::is_integral<Dst>::value) &&
(std::is_signed<Dst>::value == std::is_signed<Src>::value);
}
template <typename Src>
class to_narrow_convertible {
public:
static_assert(std::is_integral<Src>::value, "not an integer");
template <typename Dst>
struct to_ : bool_constant<detail::is_to_narrow_convertible_v<Src, Dst>> {};
public:
explicit constexpr to_narrow_convertible(Src const& value) noexcept
: value_(value) {}
#if __cplusplus >= 201703L
......@@ -419,12 +429,7 @@ class to_narrow_convertible {
to_narrow_convertible& operator=(to_narrow_convertible const&) = default;
to_narrow_convertible& operator=(to_narrow_convertible&&) = default;
template <
typename Dst,
std::enable_if_t<
std::is_integral<Dst>::value &&
std::is_signed<Dst>::value == std::is_signed<Src>::value,
int> = 0>
template <typename Dst, std::enable_if_t<to_<Dst>::value, int> = 0>
/* implicit */ constexpr operator Dst() const noexcept {
FOLLY_PUSH_WARNING
FOLLY_MSVC_DISABLE_WARNING(4244) // lossy conversion: arguments
......
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