From 1289782f06af78343ddeb8f0c1e5f63be2038abf Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Wed, 3 Jul 2019 15:50:05 -0700 Subject: [PATCH] Get rid of add_thousands_sep --- include/fmt/format.h | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/include/fmt/format.h b/include/fmt/format.h index 9b15ea10..44389e8e 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -742,26 +742,6 @@ inline int count_digits(uint32_t n) { } #endif -// A callable that adds a thousands separator. -template class add_thousands_sep { - private: - basic_string_view sep_; - - // Index of a decimal digit with the least significant digit having index 0. - unsigned digit_index_; - - public: - explicit add_thousands_sep(basic_string_view sep) - : sep_(sep), digit_index_(0) {} - - void operator()(Char*& buffer) { - if (++digit_index_ % 3 != 0) return; - buffer -= sep_.size(); - std::uninitialized_copy(sep_.data(), sep_.data() + sep_.size(), - internal::make_checked(buffer, sep_.size())); - } -}; - template FMT_API Char thousands_sep_impl(locale_ref loc); template inline Char thousands_sep(locale_ref loc) { @@ -1405,8 +1385,16 @@ template class basic_writer { template void operator()(It&& it) const { basic_string_view s(&sep, SEP_SIZE); + // Index of a decimal digit with the least significant digit having + // index 0. + unsigned digit_index = 0; it = internal::format_decimal( - it, abs_value, size, internal::add_thousands_sep(s)); + it, abs_value, size, [s, &digit_index](char_type*& buffer) { + if (++digit_index % 3 != 0) return; + buffer -= s.size(); + std::uninitialized_copy(s.data(), s.data() + s.size(), + internal::make_checked(buffer, s.size())); + }); } };