diff --git a/folly/ConstexprMath.h b/folly/ConstexprMath.h index 1e5a2ceb8fe..39f83c4f130 100644 --- a/folly/ConstexprMath.h +++ b/folly/ConstexprMath.h @@ -62,6 +62,23 @@ FOLLY_INLINE_VARIABLE constexpr double ln2 = ln2_v; } // namespace numbers +/// floating_point_integral_constant +/// +/// Like std::integral_constant but for floating-point types holding integral +/// values representable in an integral type. +template +struct floating_point_integral_constant { + using value_type = T; + static constexpr value_type value = static_cast(Value); + constexpr operator value_type() const noexcept { return value; } + constexpr value_type operator()() const noexcept { return value; } +}; +#if FOLLY_CPLUSPLUS < 201703L +template +constexpr typename floating_point_integral_constant::value_type + floating_point_integral_constant::value; +#endif + // TLDR: Prefer using operator< for ordering. And when // a and b are equivalent objects, we return b to make // sorting stable.