Skip to content

Commit

Permalink
Workaround broken numeric_limits (#1725)
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaut committed Jul 20, 2020
1 parent c228bfe commit d39d661
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,9 @@ template <typename T> constexpr T max_value() {
template <typename T> constexpr int num_bits() {
return std::numeric_limits<T>::digits;
}
// std::numeric_limits<T>::digits may return 0 for 128-bit ints.
template <> constexpr int num_bits<int128_t>() { return 128; }
template <> constexpr int num_bits<uint128_t>() { return 128; }
template <> constexpr int num_bits<fallback_uintptr>() {
return static_cast<int>(sizeof(void*) *
std::numeric_limits<unsigned char>::digits);
Expand Down Expand Up @@ -756,8 +759,8 @@ using uint32_or_64_or_128_t =
// represent all values of T.
template <typename T>
using uint32_or_64_or_128_t = conditional_t<
std::numeric_limits<T>::digits <= 32, uint32_t,
conditional_t<std::numeric_limits<T>::digits <= 64, uint64_t, uint128_t>>;
num_bits<T>() <= 32, uint32_t,
conditional_t<num_bits<T>() <= 64, uint64_t, uint128_t>>;
#endif

// Static data is placed in this class template for the header-only config.
Expand Down

0 comments on commit d39d661

Please sign in to comment.