diff --git a/fmt/format.h b/fmt/format.h index 08623343956a0..db07cac83c19b 100644 --- a/fmt/format.h +++ b/fmt/format.h @@ -910,6 +910,17 @@ class ThousandsSep { } }; +// Returns the thousands separator for the current locale. +template1)> +struct Locale { + static fmt::StringRef thousands_sep() { return ""; } +}; + +template +struct Locale { + static fmt::StringRef thousands_sep() { return static_cast(std::localeconv())->thousands_sep; } +}; + // Formats a decimal unsigned integer value writing into buffer. // thousands_sep is a functor that is called after writing each char to // add a thousands separator if necessary. @@ -2778,7 +2789,8 @@ void BasicWriter::write_int(T value, Spec spec) { } case 'n': { unsigned num_digits = internal::count_digits(abs_value); - fmt::StringRef sep = std::localeconv()->thousands_sep; + fmt::StringRef sep = + internal::Locale::thousands_sep(); unsigned size = static_cast( num_digits + sep.size() * (num_digits - 1) / 3); CharPtr p = prepare_int_buffer(size, spec, prefix, prefix_size) + 1;