diff --git a/.gitignore b/.gitignore index 76e18ec..01b9d96 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ cmake-build-release build Testing/Temporary _codeql_build_dir +_codeql_detected_source_root diff --git a/RingBuffer.hpp b/RingBuffer.hpp index 23fcc39..3c92324 100644 --- a/RingBuffer.hpp +++ b/RingBuffer.hpp @@ -49,22 +49,22 @@ namespace buffers { ring_buffer_iterator& operator=(ring_buffer_iterator const& ) noexcept = default; template::type* = nullptr> [[nodiscard]] reference operator*() noexcept { - return (*source_)[index_]; + return (*source_)[index_ % N]; } template::type* = nullptr> [[nodiscard]] const_reference operator*() const noexcept { - return (*source_)[index_]; + return (*source_)[index_ % N]; } template::type* = nullptr> [[nodiscard]] pointer operator->() noexcept { - return &((*source_)[index_]); + return &((*source_)[index_ % N]); } template::type* = nullptr> [[nodiscard]] const_pointer operator->() const noexcept { - return &((*source_)[index_]); + return &((*source_)[index_ % N]); } self_type& operator++() noexcept { - index_ = ++index_ % N; + ++index_; ++count_; return *this; } @@ -92,13 +92,13 @@ namespace buffers { template bool operator==(ring_buffer_iterator const& l, ring_buffer_iterator const& r) noexcept { - return l.source() == r.source() && l.count() == r.count() && l.index() == r.index(); + return l.source() == r.source() && l.index() == r.index(); } template bool operator!=(ring_buffer_iterator const& l, ring_buffer_iterator const& r) noexcept { - return l.source() != r.source() || l.count() != r.count() || l.index() != r.index(); + return l.source() != r.source() || l.index() != r.index(); } } @@ -214,11 +214,11 @@ using std::bool_constant; // Iterator to oldest element. [[nodiscard]] iterator begin() noexcept { return iterator{this, tail_, 0};} // Iterator to one past newest element. - [[nodiscard]] iterator end() noexcept { return iterator{this, head_, size_};} + [[nodiscard]] iterator end() noexcept { return iterator{this, tail_ + size_, size_};} // Const iterator to oldest element. [[nodiscard]] const_iterator cbegin() const noexcept { return const_iterator{this, tail_, 0};} // Const iterator to one past newest element. - [[nodiscard]] const_iterator cend() const noexcept { return const_iterator{this, head_, size_};} + [[nodiscard]] const_iterator cend() const noexcept { return const_iterator{this, tail_ + size_, size_};} // Check if buffer has no elements. [[nodiscard]] bool empty() const noexcept { return size_ == 0; } // Check if buffer is at capacity.