From d0dd6786938500b42c7f05118d1aae76c0951cd6 Mon Sep 17 00:00:00 2001 From: Barry Revzin Date: Fri, 7 Aug 2020 10:15:52 -0500 Subject: [PATCH] Adding convenience append(range) --- include/fmt/format.h | 7 +++++++ test/format-test.cc | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/include/fmt/format.h b/include/fmt/format.h index a0e35f4b..93e4b1e6 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -685,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 diff --git a/test/format-test.cc b/test/format-test.cc index 6e6b6af9..b48fd6be 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.