From 986fa00406c4ce6e2b60639ca85d36cfc58eb43c Mon Sep 17 00:00:00 2001 From: rimathia Date: Thu, 12 Nov 2020 17:37:04 +0100 Subject: [PATCH] Printf get container (#1982) * eliminate one case where basic_print_context would copy a string into a fmt::basic_memory_buffer character by character instead of using fmt::basic_memory_buffer::append * use detail::write instead of re-implementing it * use to_unsigned to avoid signedness conversion warnings --- include/fmt/printf.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/include/fmt/printf.h b/include/fmt/printf.h index b44afaba..b95b56cf 100644 --- a/include/fmt/printf.h +++ b/include/fmt/printf.h @@ -480,11 +480,13 @@ OutputIt basic_printf_context::format() { } char_type c = *it++; if (it != end && *it == c) { - out = std::copy(start, it, out); + out = detail::write( + out, basic_string_view(start, detail::to_unsigned(it - start))); start = ++it; continue; } - out = std::copy(start, it - 1, out); + out = detail::write(out, basic_string_view( + start, detail::to_unsigned(it - 1 - start))); format_specs specs; specs.align = align::right; @@ -596,7 +598,8 @@ OutputIt basic_printf_context::format() { // Format argument. out = visit_format_arg(ArgFormatter(out, specs, *this), arg); } - return std::copy(start, it, out); + return detail::write( + out, basic_string_view(start, detail::to_unsigned(it - start))); } template