Adding convenience append(range)

This commit is contained in:
Barry Revzin 2020-08-07 10:15:52 -05:00
parent d7921d649a
commit b8dc604b96
3 changed files with 8 additions and 1 deletions

View File

@ -728,6 +728,7 @@ template <typename T> class buffer {
/** Appends data to the end of the buffer. */
template <typename U> void append(const U* begin, const U* end);
template <typename ContiguousRange> void append(const ContiguousRange&);
template <typename I> T& operator[](I index) { return ptr_[index]; }
template <typename I> const T& operator[](I index) const {

View File

@ -566,6 +566,12 @@ void buffer<T>::append(const U* begin, const U* end) {
} while (begin != end);
}
template <typename T>
template <typename ContiguousRange>
void buffer<T>::append(const ContiguousRange& range) {
append(range.data(), range.data() + range.size());
}
template <typename OutputIt, typename T, typename Traits>
void iterator_buffer<OutputIt, T, Traits>::flush() {
out_ = std::copy_n(data_, this->limit(this->size()), out_);

View File

@ -236,7 +236,7 @@ TEST(MemoryBufferTest, MoveCtorInlineBuffer) {
std::allocator<char> alloc;
basic_memory_buffer<char, 5, TestAllocator> 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.