@@ -49,23 +49,27 @@ namespace buffers {
4949 ring_buffer_iterator& operator =(ring_buffer_iterator const & ) noexcept = default ;
5050 template <bool Z = C, typename std::enable_if<(!Z), int >::type* = nullptr >
5151 [[nodiscard]] reference operator *() noexcept {
52- return (*source_)[index_ % N ];
52+ return (*source_)[index_];
5353 }
5454 template <bool Z = C, typename std::enable_if<(Z), int >::type* = nullptr >
5555 [[nodiscard]] const_reference operator *() const noexcept {
56- return (*source_)[index_ % N ];
56+ return (*source_)[index_];
5757 }
5858 template <bool Z = C, typename std::enable_if<(!Z), int >::type* = nullptr >
5959 [[nodiscard]] pointer operator ->() noexcept {
60- return &((*source_)[index_ % N ]);
60+ return &((*source_)[index_]);
6161 }
6262 template <bool Z = C, typename std::enable_if<(Z), int >::type* = nullptr >
6363 [[nodiscard]] const_pointer operator ->() const noexcept {
64- return &((*source_)[index_ % N ]);
64+ return &((*source_)[index_]);
6565 }
6666 self_type& operator ++() noexcept {
67- ++index_;
6867 ++count_;
68+ if (count_ >= source_->size ()) {
69+ index_ = N; // Set to sentinel value (out of valid range [0, N-1]) when reaching end
70+ } else {
71+ index_ = (index_ + 1 ) % N;
72+ }
6973 return *this ;
7074 }
7175 self_type operator ++(int ) noexcept {
@@ -214,11 +218,11 @@ using std::bool_constant;
214218 // Iterator to oldest element.
215219 [[nodiscard]] iterator begin () noexcept { return iterator{this , tail_, 0 };}
216220 // Iterator to one past newest element.
217- [[nodiscard]] iterator end () noexcept { return iterator{this , tail_ + size_ , size_};}
221+ [[nodiscard]] iterator end () noexcept { return iterator{this , N , size_};}
218222 // Const iterator to oldest element.
219223 [[nodiscard]] const_iterator cbegin () const noexcept { return const_iterator{this , tail_, 0 };}
220224 // Const iterator to one past newest element.
221- [[nodiscard]] const_iterator cend () const noexcept { return const_iterator{this , tail_ + size_ , size_};}
225+ [[nodiscard]] const_iterator cend () const noexcept { return const_iterator{this , N , size_};}
222226 // Check if buffer has no elements.
223227 [[nodiscard]] bool empty () const noexcept { return size_ == 0 ; }
224228 // Check if buffer is at capacity.
0 commit comments