mirror of
https://github.com/fmtlib/fmt.git
synced 2025-07-30 02:37:36 +02:00
Unbloat my heart
This commit is contained in:
@ -902,6 +902,8 @@ using uint32_or_64_or_128_t =
|
|||||||
conditional_t<num_bits<T>() <= 32 && !FMT_REDUCE_INT_INSTANTIATIONS,
|
conditional_t<num_bits<T>() <= 32 && !FMT_REDUCE_INT_INSTANTIATIONS,
|
||||||
uint32_t,
|
uint32_t,
|
||||||
conditional_t<num_bits<T>() <= 64, uint64_t, uint128_t>>;
|
conditional_t<num_bits<T>() <= 64, uint64_t, uint128_t>>;
|
||||||
|
template <typename T>
|
||||||
|
using uint64_or_128_t = conditional_t<num_bits<T>() <= 64, uint64_t, uint128_t>;
|
||||||
|
|
||||||
// 128-bit integer type used internally
|
// 128-bit integer type used internally
|
||||||
struct FMT_EXTERN_TEMPLATE_API uint128_wrapper {
|
struct FMT_EXTERN_TEMPLATE_API uint128_wrapper {
|
||||||
@ -1707,6 +1709,7 @@ template <typename OutputIt, typename UInt, typename Char>
|
|||||||
OutputIt write_int_localized(OutputIt out, UInt value, string_view prefix,
|
OutputIt write_int_localized(OutputIt out, UInt value, string_view prefix,
|
||||||
const basic_format_specs<Char>& specs,
|
const basic_format_specs<Char>& specs,
|
||||||
locale_ref loc) {
|
locale_ref loc) {
|
||||||
|
static_assert(std::is_same<uint64_or_128_t<UInt>, UInt>::value, "");
|
||||||
const auto sep_size = 1;
|
const auto sep_size = 1;
|
||||||
std::string groups = grouping<Char>(loc);
|
std::string groups = grouping<Char>(loc);
|
||||||
if (groups.empty()) return write_dec(out, value, prefix, specs);
|
if (groups.empty()) return write_dec(out, value, prefix, specs);
|
||||||
@ -1759,11 +1762,9 @@ template <typename OutputIt, typename T, typename Char>
|
|||||||
FMT_CONSTEXPR OutputIt write_int(OutputIt out, T value,
|
FMT_CONSTEXPR OutputIt write_int(OutputIt out, T value,
|
||||||
const basic_format_specs<Char>& specs,
|
const basic_format_specs<Char>& specs,
|
||||||
locale_ref loc) {
|
locale_ref loc) {
|
||||||
using uint_type = uint32_or_64_or_128_t<T>;
|
|
||||||
auto abs_value = static_cast<uint_type>(value);
|
|
||||||
|
|
||||||
char prefix[4] = {};
|
char prefix[4] = {};
|
||||||
auto prefix_size = 0u;
|
auto prefix_size = 0u;
|
||||||
|
auto abs_value = static_cast<uint32_or_64_or_128_t<T>>(value);
|
||||||
if (is_negative(value)) {
|
if (is_negative(value)) {
|
||||||
prefix[0] = '-';
|
prefix[0] = '-';
|
||||||
++prefix_size;
|
++prefix_size;
|
||||||
@ -1772,13 +1773,13 @@ FMT_CONSTEXPR OutputIt write_int(OutputIt out, T value,
|
|||||||
prefix[0] = specs.sign == sign::plus ? '+' : ' ';
|
prefix[0] = specs.sign == sign::plus ? '+' : ' ';
|
||||||
++prefix_size;
|
++prefix_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (specs.type) {
|
switch (specs.type) {
|
||||||
case 0:
|
case 0:
|
||||||
case 'd':
|
case 'd':
|
||||||
return specs.localized
|
return specs.localized
|
||||||
? write_int_localized(out, abs_value, {prefix, prefix_size},
|
? write_int_localized(out,
|
||||||
specs, loc)
|
static_cast<uint64_or_128_t<T>>(abs_value),
|
||||||
|
{prefix, prefix_size}, specs, loc)
|
||||||
: write_dec(out, abs_value, {prefix, prefix_size}, specs);
|
: write_dec(out, abs_value, {prefix, prefix_size}, specs);
|
||||||
case 'x':
|
case 'x':
|
||||||
case 'X': {
|
case 'X': {
|
||||||
|
Reference in New Issue
Block a user