Adding convenience append(range)
This commit is contained in:
parent
d7921d649a
commit
b8dc604b96
@ -728,6 +728,7 @@ template <typename T> class buffer {
|
|||||||
|
|
||||||
/** Appends data to the end of the buffer. */
|
/** Appends data to the end of the buffer. */
|
||||||
template <typename U> void append(const U* begin, const U* end);
|
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> T& operator[](I index) { return ptr_[index]; }
|
||||||
template <typename I> const T& operator[](I index) const {
|
template <typename I> const T& operator[](I index) const {
|
||||||
|
|||||||
@ -566,6 +566,12 @@ void buffer<T>::append(const U* begin, const U* end) {
|
|||||||
} while (begin != 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>
|
template <typename OutputIt, typename T, typename Traits>
|
||||||
void iterator_buffer<OutputIt, T, Traits>::flush() {
|
void iterator_buffer<OutputIt, T, Traits>::flush() {
|
||||||
out_ = std::copy_n(data_, this->limit(this->size()), out_);
|
out_ = std::copy_n(data_, this->limit(this->size()), out_);
|
||||||
|
|||||||
@ -236,7 +236,7 @@ TEST(MemoryBufferTest, MoveCtorInlineBuffer) {
|
|||||||
std::allocator<char> alloc;
|
std::allocator<char> alloc;
|
||||||
basic_memory_buffer<char, 5, TestAllocator> buffer((TestAllocator(&alloc)));
|
basic_memory_buffer<char, 5, TestAllocator> buffer((TestAllocator(&alloc)));
|
||||||
const char test[] = "test";
|
const char test[] = "test";
|
||||||
buffer.append(test, test + 4);
|
buffer.append(string_view(test, 4));
|
||||||
check_move_buffer("test", buffer);
|
check_move_buffer("test", buffer);
|
||||||
// Adding one more character fills the inline buffer, but doesn't cause
|
// Adding one more character fills the inline buffer, but doesn't cause
|
||||||
// dynamic allocation.
|
// dynamic allocation.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user