39 const T &
operator[](
const size_t offset)
const;
49 template <
typename... Args>
56 const T &
front(
void)
const;
66 template <
typename... Args>
73 const T &
back(
void)
const;
79 bool empty(
void)
const;
82 bool full(
void)
const;
85 size_t size(
void)
const;
100 std::vector<T> _container;
103 template <
typename T>
113 template <
typename T>
116 _backIndex(capacity-1),
120 assert(capacity > 0);
123 template <
typename T>
126 return _container[(_frontIndex + offset) % _container.size()];
129 template <
typename T>
132 return _container[(_frontIndex + offset) % _container.size()];
135 template <
typename T>
136 template <
typename U>
139 assert(not this->
full());
140 _frontIndex = size_t(_frontIndex + _container.size() - 1) % _container.size();
141 _container[_frontIndex] = std::forward<U>(elem);
145 template <
typename T>
146 template <
typename... Args>
149 assert(not this->
full());
150 _frontIndex = size_t(_frontIndex + _container.size() - 1) % _container.size();
151 _container[_frontIndex] = T(std::forward<Args>(args)...);
153 return _container[_frontIndex];
156 template <
typename T>
159 assert(not this->
empty());
160 assert(_frontIndex < _container.size());
161 _container[_frontIndex] = T();
162 _frontIndex = size_t(_frontIndex + 1) % _container.size();
166 template <
typename T>
169 assert(not this->
empty());
170 assert(_frontIndex < _container.size());
171 return _container[_frontIndex];
174 template <
typename T>
177 assert(not this->
empty());
178 assert(_frontIndex < _container.size());
179 return _container[_frontIndex];
182 template <
typename T>
183 template <
typename U>
186 assert(not this->
full());
187 _backIndex = size_t(_backIndex + 1) % _container.size();
188 _container[_backIndex] = std::forward<U>(elem);
192 template <
typename T>
193 template <
typename... Args>
196 assert(not this->
full());
197 _backIndex = size_t(_backIndex + 1) % _container.size();
198 _container[_backIndex] = T(std::forward<Args>(args)...);
200 return _container[_backIndex];
203 template <
typename T>
206 assert(not this->
empty());
207 assert(_backIndex < _container.size());
208 _container[_backIndex] = T();
209 _backIndex = size_t(_backIndex + _container.size() - 1) % _container.size();
213 template <
typename T>
216 assert(not this->
empty());
217 assert(_backIndex < _container.size());
218 return _container[_backIndex];
221 template <
typename T>
224 assert(not this->
empty());
225 assert(_backIndex < _container.size());
226 return _container[_backIndex];
229 template <
typename T>
232 return _numElements == 0;
235 template <
typename T>
238 return _numElements == _container.size();
241 template <
typename T>
247 template <
typename T>
250 return _container.size();
253 template <
typename T>
256 if (_numElements > capacity)
return;
257 std::vector<T> _newContainer(capacity);
258 for (
size_t i = 0; i < _numElements; i++)
260 _newContainer[i] = _container[(_frontIndex+i) % _container.size()];
262 _container = _newContainer;
264 _backIndex = (_numElements + capacity - 1) % capacity;
267 template <
typename T>
270 while (not this->
empty())
const T & operator[](const size_t offset) const
Get a const ref at, where front == 0, back == size() - 1.
Definition: RingDeque.hpp:124
size_t capacity(void) const
How many elements can be stored?
Definition: RingDeque.hpp:248
void pop_back(void)
Pop and element from the back of the queue.
Definition: RingDeque.hpp:204
T & emplace_front(Args &&...args)
Emplace an element onto the front of the queue.
Definition: RingDeque.hpp:147
size_t size(void) const
How many elements are in the deque.
Definition: RingDeque.hpp:242
Definition: Testing.hpp:134
bool empty(void) const
Is the deque empty? – no elements.
Definition: RingDeque.hpp:230
void push_front(U &&elem)
Push an element onto the front of the queue.
Definition: RingDeque.hpp:137
void set_capacity(const size_t capacity)
Set the deque capacity if too small.
Definition: RingDeque.hpp:254
void clear(void)
Empty the contents of this queue.
Definition: RingDeque.hpp:268
RingDeque(void)
Construct a new ring deque.
Definition: RingDeque.hpp:104
void pop_front(void)
Pop and element from the front of the queue.
Definition: RingDeque.hpp:157
Definition: RingDeque.hpp:29
T & emplace_back(Args &&...args)
Emplace an element onto the back of the queue.
Definition: RingDeque.hpp:194
const T & front(void) const
Get a const reference to the front element.
Definition: RingDeque.hpp:167
bool full(void) const
Is the deque full? – num elements == capacity.
Definition: RingDeque.hpp:236
const T & back(void) const
Get a const reference to the back element.
Definition: RingDeque.hpp:214
void push_back(U &&elem)
Push an element onto the back of the queue.
Definition: RingDeque.hpp:184