make basic_ring_buffer fulfull its own template parameter requirements

This commit is contained in:
Ferdinand Bachmann
2020-04-22 15:52:07 +02:00
parent fd04982754
commit f1562b7960
2 changed files with 15 additions and 1 deletions

View File

@ -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.

View File

@ -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;
}