diff --git a/README.md b/README.md index ab911d9..952c9cf 100644 --- a/README.md +++ b/README.md @@ -70,12 +70,15 @@ The iterators returned by `begin()`, `end()`, `begin() const`, `end() const`, after the logical last element. (i.e., they wrap around if they reach the end of the underlying container) +`basic_ring_buffer` fulfills its own template parameter requirements. + #### Template parameter requirements The parameter `Container` needs to have member types `value_type` and `size_type`, and methods `size_type size() const`, `iterator begin()`, `iterator end()`, `const_iterator cbegin() const`, and `const_iterator cend() -const`, as well as an overloaded `value_type& operator[](size_type)`. +const`, as well as an overloaded `value_type& operator[](size_type)` and `const +value_type& operator[](size_type) const)`. The iterators returned by the container need to be random access iterators. diff --git a/include/ring-buffer.h b/include/ring-buffer.h index 6cf6d70..ee85626 100644 --- a/include/ring-buffer.h +++ b/include/ring-buffer.h @@ -27,6 +27,17 @@ public: basic_ring_buffer& operator=(const basic_ring_buffer& other) = default; basic_ring_buffer& operator=(basic_ring_buffer&& other) = default; + CONSTEXPR size_type size() const NOEXCEPT { + return container.size(); + } + + CONSTEXPR value_type& operator[](size_type size) COND_NOEXCEPT(noexcept(container[size])) { + return container[size]; + } + CONSTEXPR const value_type& operator[](size_type size) const COND_NOEXCEPT(noexcept(container[size])) { + return container[size]; + } + CONSTEXPR Container& buffer() NOEXCEPT { return container; }