Reduce the numer of ifdefs with an empty (u)int128_t fallback

This commit is contained in:
Victor Zverovich
2019-09-05 17:43:40 -07:00
parent 6de0454b42
commit 1882b9687b
3 changed files with 48 additions and 63 deletions

View File

@@ -636,20 +636,12 @@ FMT_CONSTEXPR bool is_negative(T) {
return false;
}
#if FMT_USE_INT128
// Smallest of uint32_t, uint64_t, unsigned __int128 that is large enough to
// Smallest of uint32_t, uint64_t, uint128_t that is large enough to
// 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>>;
#else
// Smallest of uint32_t and uint64_t that is large enough to 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, uint64_t>;
#endif
conditional_t<std::numeric_limits<T>::digits <= 64, uint64_t, uint128_t>>;
// Static data is placed in this class template for the header-only config.
template <typename T = void> struct FMT_EXTERN_TEMPLATE_API basic_data {
@@ -699,7 +691,7 @@ inline int count_digits(uint64_t n) {
#endif
#if FMT_USE_INT128
inline int count_digits(__uint128_t n) {
inline int count_digits(uint128_t n) {
int count = 1;
for (;;) {
// Integer division is slow so do it for a group of four digits instead
@@ -847,12 +839,8 @@ inline Char* format_decimal(Char* buffer, UInt value, int num_digits,
template <typename Int> constexpr int digits10() noexcept {
return std::numeric_limits<Int>::digits10;
}
#if FMT_USE_INT128
template <> constexpr int digits10<__int128_t>() noexcept { return 38; }
template <> constexpr int digits10<__uint128_t>() noexcept { return 38; }
#endif
template <> constexpr int digits10<int128_t>() noexcept { return 38; }
template <> constexpr int digits10<uint128_t>() noexcept { return 38; }
template <typename Char, typename UInt, typename Iterator, typename F>
inline Iterator format_decimal(Iterator out, UInt value, int num_digits,
@@ -1644,15 +1632,14 @@ template <typename Range> class basic_writer {
void write(int value) { write_decimal(value); }
void write(long value) { write_decimal(value); }
void write(long long value) { write_decimal(value); }
#if FMT_USE_INT128
void write(__int128_t value) { write_decimal(value); }
#endif
void write(unsigned value) { write_decimal(value); }
void write(unsigned long value) { write_decimal(value); }
void write(unsigned long long value) { write_decimal(value); }
#if FMT_USE_INT128
void write(__uint128_t value) { write_decimal(value); }
void write(int128_t value) { write_decimal(value); }
void write(uint128_t value) { write_decimal(value); }
#endif
// Writes a formatted integer.
@@ -1737,12 +1724,8 @@ template <typename Range> class basic_writer {
using writer = basic_writer<buffer_range<char>>;
template <typename T> struct is_integral : std::is_integral<T> {};
#if FMT_USE_INT128
template <> struct is_integral<__int128_t> : std::true_type {};
template <> struct is_integral<__uint128_t> : std::true_type {};
#endif
template <> struct is_integral<int128_t> : std::true_type {};
template <> struct is_integral<uint128_t> : std::true_type {};
template <typename Range, typename ErrorHandler = internal::error_handler>
class arg_formatter_base {