From 065889a5937e01157eb5278c5865340d55a0b6c6 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sat, 8 Aug 2020 07:01:21 -0700 Subject: [PATCH] Use correct capacity in iterator_buffer (#1807) --- include/fmt/core.h | 2 +- test/format-test.cc | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/include/fmt/core.h b/include/fmt/core.h index 359deb25..f8b2c709 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -771,7 +771,7 @@ class iterator_buffer : public Traits, public buffer { void flush(); public: - explicit iterator_buffer(OutputIt out, size_t n = 0) + explicit iterator_buffer(OutputIt out, size_t n = buffer_size) : Traits(n), buffer(data_, 0, n < size_t(buffer_size) ? n : size_t(buffer_size)), out_(out) {} diff --git a/test/format-test.cc b/test/format-test.cc index b48fd6be..bd3dcfdb 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -1946,6 +1946,12 @@ TEST(FormatTest, FormattedSize) { EXPECT_EQ(2u, fmt::formatted_size("{}", 42)); } +TEST(FormatTest, FormatTo) { + std::vector v; + fmt::format_to(std::back_inserter(v), "{}", "foo"); + EXPECT_EQ(string_view(v.data(), v.size()), "foo"); +} + TEST(FormatTest, FormatToN) { char buffer[4]; buffer[3] = 'x';