From b8dc604b9604dbcea77c86f87aaa745f99c18a8c Mon Sep 17 00:00:00 2001 From: Barry Revzin Date: Fri, 7 Aug 2020 10:15:52 -0500 Subject: [PATCH 1/2] Adding convenience append(range) --- include/fmt/core.h | 1 + include/fmt/format.h | 6 ++++++ test/format-test.cc | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/include/fmt/core.h b/include/fmt/core.h index 76569a2dbdac..75c04fd81a97 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -728,6 +728,7 @@ template class buffer { /** Appends data to the end of the buffer. */ template void append(const U* begin, const U* end); + template void append(const ContiguousRange&); template T& operator[](I index) { return ptr_[index]; } template const T& operator[](I index) const { diff --git a/include/fmt/format.h b/include/fmt/format.h index a0e35f4b3f06..ab208c89f1da 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -566,6 +566,12 @@ void buffer::append(const U* begin, const U* end) { } while (begin != end); } +template +template +void buffer::append(const ContiguousRange& range) { + append(range.data(), range.data() + range.size()); +} + template void iterator_buffer::flush() { out_ = std::copy_n(data_, this->limit(this->size()), out_); diff --git a/test/format-test.cc b/test/format-test.cc index 6e6b6af9e0e8..b48fd6be6ef2 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -236,7 +236,7 @@ TEST(MemoryBufferTest, MoveCtorInlineBuffer) { std::allocator alloc; basic_memory_buffer buffer((TestAllocator(&alloc))); const char test[] = "test"; - buffer.append(test, test + 4); + buffer.append(string_view(test, 4)); check_move_buffer("test", buffer); // Adding one more character fills the inline buffer, but doesn't cause // dynamic allocation. From 6d547402958c4980e9eb409d3d07a209d93c511c Mon Sep 17 00:00:00 2001 From: Barry Revzin Date: Fri, 7 Aug 2020 12:04:41 -0500 Subject: [PATCH 2/2] Moving append to basic_memory_buffer. --- include/fmt/core.h | 1 - include/fmt/format.h | 13 +++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/include/fmt/core.h b/include/fmt/core.h index 75c04fd81a97..76569a2dbdac 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -728,7 +728,6 @@ template class buffer { /** Appends data to the end of the buffer. */ template void append(const U* begin, const U* end); - template void append(const ContiguousRange&); template T& operator[](I index) { return ptr_[index]; } template const T& operator[](I index) const { diff --git a/include/fmt/format.h b/include/fmt/format.h index ab208c89f1da..93e4b1e62339 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -566,12 +566,6 @@ void buffer::append(const U* begin, const U* end) { } while (begin != end); } -template -template -void buffer::append(const ContiguousRange& range) { - append(range.data(), range.data() + range.size()); -} - template void iterator_buffer::flush() { out_ = std::copy_n(data_, this->limit(this->size()), out_); @@ -691,6 +685,13 @@ class basic_memory_buffer : public detail::buffer { /** Increases the buffer capacity to *new_capacity*. */ void reserve(size_t new_capacity) { this->try_reserve(new_capacity); } + + // Directly append data into the buffer + using detail::buffer::append; + template + void append(const ContiguousRange& range) { + append(range.data(), range.data() + range.size()); + } }; template