Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ cmake-build-release
build
Testing/Temporary
_codeql_build_dir
_codeql_detected_source_root

18 changes: 9 additions & 9 deletions RingBuffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,22 @@ namespace buffers {
ring_buffer_iterator& operator=(ring_buffer_iterator const& ) noexcept = default;
template<bool Z = C, typename std::enable_if<(!Z), int>::type* = nullptr>
[[nodiscard]] reference operator*() noexcept {
return (*source_)[index_];
return (*source_)[index_ % N];
}
template<bool Z = C, typename std::enable_if<(Z), int>::type* = nullptr>
[[nodiscard]] const_reference operator*() const noexcept {
return (*source_)[index_];
return (*source_)[index_ % N];
}
template<bool Z = C, typename std::enable_if<(!Z), int>::type* = nullptr>
[[nodiscard]] pointer operator->() noexcept {
return &((*source_)[index_]);
return &((*source_)[index_ % N]);
}
template<bool Z = C, typename std::enable_if<(Z), int>::type* = nullptr>
[[nodiscard]] const_pointer operator->() const noexcept {
return &((*source_)[index_]);
return &((*source_)[index_ % N]);
}
self_type& operator++() noexcept {
index_ = ++index_ % N;
++index_;
Copy link
Owner

@bugparty bugparty Jan 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你这个改动和之前的代码不是等效的吗,为什么要这样做 @copilot

++count_;
return *this;
}
Expand Down Expand Up @@ -92,13 +92,13 @@ namespace buffers {
template<typename T, size_t N, bool C, bool Overwrite>
bool operator==(ring_buffer_iterator<T,N,C,Overwrite> const& l,
ring_buffer_iterator<T,N,C,Overwrite> 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<typename T, size_t N, bool C, bool Overwrite>
bool operator!=(ring_buffer_iterator<T,N,C,Overwrite> const& l,
ring_buffer_iterator<T,N,C,Overwrite> 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();
}

}
Expand Down Expand Up @@ -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.
Expand Down