From 16aec06179a2c2661be77fd9ba3b202955de0c0b Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sun, 31 May 2020 10:58:52 -0700 Subject: [PATCH] Cleanup arg_formatter_base --- include/fmt/format.h | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/include/fmt/format.h b/include/fmt/format.h index a9205677..8bb854f5 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -1621,6 +1621,16 @@ OutputIt write(OutputIt out, T value, basic_format_specs specs = {}, return write_padded(out, specs, w.size(), w); } +template +OutputIt write_char(OutputIt out, Char value, + const basic_format_specs& specs) { + using iterator = remove_reference_t; + return write_padded(out, specs, 1, [=](iterator it) { + *it++ = value; + return it; + }); +} + template OutputIt write(OutputIt out, basic_string_view s, const basic_format_specs& specs = {}) { @@ -1660,8 +1670,8 @@ template class arg_formatter_base { public: - using char_type = Char; using iterator = OutputIt; + using char_type = Char; using format_specs = basic_format_specs; private: @@ -1678,24 +1688,6 @@ class arg_formatter_base { using reserve_iterator = remove_reference_t(), 0))>; - struct char_writer { - char_type value; - - size_t size() const { return 1; } - - template It operator()(It it) const { - *it++ = value; - return it; - } - }; - - void write_char(char_type value) { - if (specs_) - out_ = write_padded(out_, *specs_, 1, char_writer{value}); - else - write(value); - } - // Writes a decimal integer. template void write_decimal(Int value) { auto abs_value = static_cast>(value); @@ -1840,7 +1832,12 @@ class arg_formatter_base { else formatter.write(value); } - void on_char() { formatter.write_char(value); } + void on_char() { + if (formatter.specs_) + formatter.out_ = write_char(formatter.out_, value, *formatter.specs_); + else + formatter.write(value); + } }; struct cstring_spec_handler : detail::error_handler {