From 6684314ccd2b48b32f5884b43d1ddd9133bb755d Mon Sep 17 00:00:00 2001 From: rimathia Date: Fri, 13 Nov 2020 20:38:57 +0100 Subject: [PATCH] add specialization of copy_str instead of using detail::write in it --- include/fmt/format.h | 66 +++++++++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 29 deletions(-) diff --git a/include/fmt/format.h b/include/fmt/format.h index e04d4338..4e461f7d 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -605,6 +605,14 @@ OutputIt copy_str(InputIt begin, InputIt end, OutputIt it) { return it; } +template ::value)> +buffer_appender copy_str(InputIt begin, InputIt end, + buffer_appender out) { + get_container(out).append(begin, end); + return out; +} + template inline counting_iterator copy_str(InputIt begin, InputIt end, counting_iterator it) { @@ -1518,34 +1526,6 @@ FMT_NOINLINE OutputIt fill(OutputIt it, size_t n, const fill_t& fill) { return it; } -template -OutputIt write(OutputIt out, monostate) { - FMT_ASSERT(false, ""); - return out; -} - -template ::value)> -OutputIt write(OutputIt out, string_view value) { - auto it = reserve(out, value.size()); - it = copy_str(value.begin(), value.end(), it); - return base_iterator(out, it); -} - -template -OutputIt write(OutputIt out, basic_string_view value) { - auto it = reserve(out, value.size()); - it = copy_str(value.begin(), value.end(), it); - return base_iterator(out, it); -} - -template -buffer_appender write(buffer_appender out, - basic_string_view value) { - get_container(out).append(value.begin(), value.end()); - return out; -} - // Writes the output of f, padded according to format specifications in specs. // size: output size in code units. // width: output display width in (terminal) column positions. @@ -1635,7 +1615,7 @@ OutputIt write(OutputIt out, basic_string_view s, : 0; using iterator = remove_reference_t; return write_padded(out, specs, size, width, [=](iterator it) { - return detail::write(it, basic_string_view(data, size)); + return copy_str(data, data + size, it); }); } @@ -2062,6 +2042,34 @@ template struct is_integral : std::is_integral {}; template <> struct is_integral : std::true_type {}; template <> struct is_integral : std::true_type {}; +template +OutputIt write(OutputIt out, monostate) { + FMT_ASSERT(false, ""); + return out; +} + +template ::value)> +OutputIt write(OutputIt out, string_view value) { + auto it = reserve(out, value.size()); + it = copy_str(value.begin(), value.end(), it); + return base_iterator(out, it); +} + +template +OutputIt write(OutputIt out, basic_string_view value) { + auto it = reserve(out, value.size()); + it = copy_str(value.begin(), value.end(), it); + return base_iterator(out, it); +} + +template +buffer_appender write(buffer_appender out, + basic_string_view value) { + get_container(out).append(value.begin(), value.end()); + return out; +} + template ::value && !std::is_same::value &&