From 7b4429dfedb616b12af02a963ca9d49856e9ab4c Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Tue, 18 Jun 2024 18:15:46 +0100 Subject: [PATCH] Ring buffer: Add input iterator pair constructor --- src/core/ring_buffer.hpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/core/ring_buffer.hpp b/src/core/ring_buffer.hpp index 837173ae43..8593be1228 100644 --- a/src/core/ring_buffer.hpp +++ b/src/core/ring_buffer.hpp @@ -252,6 +252,24 @@ public: } } + template ::iterator_category, std::input_iterator_tag>::value>> + ring_buffer(InputIt first, InputIt last) + { + if (first == last) return; + + uint32_t size = (uint32_t)std::distance(first, last); + uint32_t cap = round_up_size(size); + this->data.reset(MallocT(cap * sizeof(T))); + this->mask = cap - 1; + this->head = 0; + this->count = size; + uint8_t *ptr = this->data.get(); + for (auto iter = first; iter != last; ++iter) { + new (ptr) T(*iter); + ptr += sizeof(T); + } + } + ring_buffer& operator =(const ring_buffer &other) { if (&other != this) {