Skip to content

Commit

Permalink
floating_point_integral_constant
Browse files Browse the repository at this point in the history
Summary: Like `std::integral_constant`, but for holding integral values of floating-point type representable in an integral type.

Reviewed By: ispeters

Differential Revision: D48483298

fbshipit-source-id: 68e712da695e38503b3a89d2eeb73dad515d0e1f
  • Loading branch information
yfeldblum authored and facebook-github-bot committed Aug 22, 2023
1 parent 9746a85 commit c8deb52
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions folly/ConstexprMath.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,23 @@ FOLLY_INLINE_VARIABLE constexpr double ln2 = ln2_v<double>;

} // namespace numbers

/// floating_point_integral_constant
///
/// Like std::integral_constant but for floating-point types holding integral
/// values representable in an integral type.
template <typename T, typename S, S Value>
struct floating_point_integral_constant {
using value_type = T;
static constexpr value_type value = static_cast<value_type>(Value);
constexpr operator value_type() const noexcept { return value; }
constexpr value_type operator()() const noexcept { return value; }
};
#if FOLLY_CPLUSPLUS < 201703L
template <typename T, typename S, S Value>
constexpr typename floating_point_integral_constant<T, S, Value>::value_type
floating_point_integral_constant<T, S, Value>::value;
#endif

// TLDR: Prefer using operator< for ordering. And when
// a and b are equivalent objects, we return b to make
// sorting stable.
Expand Down

0 comments on commit c8deb52

Please sign in to comment.