From b8dc604b9604dbcea77c86f87aaa745f99c18a8c 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/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 76569a2d..75c04fd8 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 a0e35f4b..ab208c89 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 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.