Skip to content
Open
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
14 changes: 14 additions & 0 deletions include/circular_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,21 @@ namespace jm {
{
return JM_CB_ADDRESSOF(_buffer[0]._value);
}

JM_CB_CXX14_CONSTEXPR reference operator[](size_type i) JM_CB_NOEXCEPT
{
return _buffer[(_head + i) % N]._value;
}

JM_CB_CXX14_CONSTEXPR reference at(size_type i)
{
if (i >= N)
{
throw std::out_of_range("Array index error");

@JustasMasiulis JustasMasiulis Nov 8, 2020

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Hey, sorry for not replying to your issue and thanks for the additions 👍

However, could you change the exception message to circular_buffer::at index out of range to reflect the source of exception better?

Edit: now that I'm thinking about it, it should check whether index is within bounds of valid elements, not just allocation, so that would need to be fixed too

}
return _buffer[(_head + i) % N]._value;
}

/// modifiers
void push_back(const value_type& value)
{
Expand Down