diff --git a/include/fmt/format.h b/include/fmt/format.h index 90cfb904..1dd9e26b 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -902,6 +902,8 @@ using uint32_or_64_or_128_t = conditional_t() <= 32 && !FMT_REDUCE_INT_INSTANTIATIONS, uint32_t, conditional_t() <= 64, uint64_t, uint128_t>>; +template +using uint64_or_128_t = conditional_t() <= 64, uint64_t, uint128_t>; // 128-bit integer type used internally struct FMT_EXTERN_TEMPLATE_API uint128_wrapper { @@ -1707,6 +1709,7 @@ template OutputIt write_int_localized(OutputIt out, UInt value, string_view prefix, const basic_format_specs& specs, locale_ref loc) { + static_assert(std::is_same, UInt>::value, ""); const auto sep_size = 1; std::string groups = grouping(loc); if (groups.empty()) return write_dec(out, value, prefix, specs); @@ -1759,11 +1762,9 @@ template FMT_CONSTEXPR OutputIt write_int(OutputIt out, T value, const basic_format_specs& specs, locale_ref loc) { - using uint_type = uint32_or_64_or_128_t; - auto abs_value = static_cast(value); - char prefix[4] = {}; auto prefix_size = 0u; + auto abs_value = static_cast>(value); if (is_negative(value)) { prefix[0] = '-'; ++prefix_size; @@ -1772,13 +1773,13 @@ FMT_CONSTEXPR OutputIt write_int(OutputIt out, T value, prefix[0] = specs.sign == sign::plus ? '+' : ' '; ++prefix_size; } - switch (specs.type) { case 0: case 'd': return specs.localized - ? write_int_localized(out, abs_value, {prefix, prefix_size}, - specs, loc) + ? write_int_localized(out, + static_cast>(abs_value), + {prefix, prefix_size}, specs, loc) : write_dec(out, abs_value, {prefix, prefix_size}, specs); case 'x': case 'X': {