Use correct capacity in iterator_buffer (#1807)

This commit is contained in:
Victor Zverovich 2020-08-08 07:01:21 -07:00
parent d0dd678693
commit 065889a593
2 changed files with 7 additions and 1 deletions

View File

@ -771,7 +771,7 @@ class iterator_buffer : public Traits, public buffer<T> {
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<T>(data_, 0, n < size_t(buffer_size) ? n : size_t(buffer_size)),
out_(out) {}

View File

@ -1946,6 +1946,12 @@ TEST(FormatTest, FormattedSize) {
EXPECT_EQ(2u, fmt::formatted_size("{}", 42));
}
TEST(FormatTest, FormatTo) {
std::vector<char> 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';