diff --git a/include/fmt/format.h b/include/fmt/format.h index b18303b0..08a01914 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -638,6 +638,7 @@ void iterator_buffer::flush() { out_ = copy_str(data_, data_ + this->limit(this->size()), out_); this->clear(); } + } // namespace detail // The number of characters to store in the basic_memory_buffer object itself @@ -1518,6 +1519,34 @@ 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. @@ -1607,7 +1636,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 copy_str(data, data + size, it); + return detail::write(it, basic_string_view(data, size)); }); } @@ -2034,34 +2063,6 @@ 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 &&