From 5a6309dc282447eed8bf1756afbba6e4b3caa675 Mon Sep 17 00:00:00 2001 From: Ferdinand Bachmann Date: Wed, 10 Mar 2021 13:46:27 +0100 Subject: [PATCH] ring_buffer_iterator: add it1 - it2 operator --- include/ring-buffer-iterator.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/ring-buffer-iterator.h b/include/ring-buffer-iterator.h index 9e207a2..f11fc0f 100644 --- a/include/ring-buffer-iterator.h +++ b/include/ring-buffer-iterator.h @@ -41,6 +41,10 @@ public: return {*container_ptr, front, index - n}; } + CONSTEXPR difference_type operator-(const ring_buffer_iterator& other) const NOEXCEPT { + return index - other.index; + } + CONSTEXPR reference operator*() COND_NOEXCEPT(noexcept(container_ptr->begin()) && noexcept(container_ptr->size())) { return *(container_ptr->begin() + (front + index) % container_ptr->size()); } @@ -137,6 +141,10 @@ public: return {*container_ptr, front, index - n}; } + CONSTEXPR difference_type operator-(const ring_buffer_const_iterator& other) const NOEXCEPT { + return index - other.index; + } + CONSTEXPR reference operator*() const COND_NOEXCEPT(noexcept(container_ptr->cbegin()) && noexcept(container_ptr->size())) { return *(container_ptr->cbegin() + (front + index) % container_ptr->size()); }