25template<
class T,
class Alloc = std::allocator<T>>
48 TsDeque(
typename std::deque<T, Alloc>::size_type count,
const T& value,
const Alloc& alloc = Alloc())
49 : _queue(count, value, alloc) {}
54 explicit TsDeque(
typename std::deque<T, Alloc>::size_type count,
const Alloc& alloc = Alloc())
55 : _queue(count, alloc) {}
61 template<
class InputIt>
62 TsDeque(InputIt first, InputIt last,
const Alloc& alloc = Alloc())
63 : _queue(first, last, alloc)
70 std::scoped_lock lk(other._mutex);
71 _queue = std::deque<T, Alloc>(other._queue);
78 std::scoped_lock lk(other._mutex);
79 _queue = std::deque<T, Alloc>(other._queue, alloc);
86 std::scoped_lock lk(other._mutex);
87 _queue = std::deque<T, Alloc>(std::move(other._queue));
95 std::scoped_lock lk(other._mutex);
96 _queue = std::deque<T, Alloc>(std::move(other._queue), alloc);
101 TsDeque(std::initializer_list<T> init,
const Alloc& alloc = Alloc())
102 : _queue(init, alloc) {}
109 std::scoped_lock lk(_mutex);
110 std::scoped_lock lko(other._mutex);
111 _queue = other._queue;
120 std::scoped_lock lk(_mutex);
121 std::scoped_lock lko(other._mutex);
122 _queue = std::move(other._queue);
138 void assign(
typename std::deque<T, Alloc>::size_type count,
const T& value)
140 std::scoped_lock lk(_mutex);
141 _queue.assign(count, value);
149 template<
class InputIt>
152 std::scoped_lock lk(_mutex);
153 _queue.assign(first, last);
159 void assign(std::initializer_list<T> ilist)
161 std::scoped_lock lk(_mutex);
162 _queue.assign(ilist);
167 typename std::deque<T, Alloc>::allocator_type
get_allocator() const noexcept
169 return _queue.get_allocator();
180 auto&
at(
typename std::deque<T, Alloc>::size_type pos) {
return _queue.at(pos); }
185 const auto&
at(
typename std::deque<T, Alloc>::size_type pos)
const {
return _queue.at(pos); }
190 auto&
operator[](
typename std::deque<T, Alloc>::size_type pos) {
return _queue[pos]; }
194 const auto&
operator[](
typename std::deque<T, Alloc>::size_type pos)
const {
return _queue[pos]; }
198 auto&
front() {
return _queue.front(); }
201 const auto&
front()
const {
return _queue.front(); }
205 auto&
back() {
return _queue.back(); }
208 const auto&
back()
const {
return _queue.back(); }
217 typename std::deque<T>::iterator
begin() noexcept {
return _queue.begin(); }
221 typename std::deque<T>::const_iterator
begin() const noexcept {
return _queue.begin(); }
225 typename std::deque<T>::const_iterator
cbegin() const noexcept {
return _queue.cbegin(); }
230 typename std::deque<T>::iterator
end() noexcept {
return _queue.end(); }
234 typename std::deque<T>::const_iterator
end() const noexcept {
return _queue.end(); }
238 typename std::deque<T>::const_iterator
cend() const noexcept {
return _queue.cend(); }
243 typename std::deque<T>::reverse_iterator
rbegin() noexcept {
return _queue.rbegin(); }
247 typename std::deque<T>::const_reverse_iterator
rbegin() const noexcept {
return _queue.rbegin(); }
251 typename std::deque<T>::const_reverse_iterator
crbegin() const noexcept {
return _queue.crbegin(); }
257 typename std::deque<T>::reverse_iterator
rend() noexcept {
return _queue.rend(); }
262 typename std::deque<T>::const_reverse_iterator
rend() const noexcept {
return _queue.rend(); }
267 typename std::deque<T>::const_reverse_iterator
crend() const noexcept {
return _queue.crend(); }
275 [[nodiscard]]
bool empty() const noexcept
277 std::scoped_lock lk(_mutex);
278 return _queue.empty();
283 typename std::deque<T, Alloc>::size_type
size() const noexcept
285 std::scoped_lock lk(_mutex);
286 return _queue.size();
291 typename std::deque<T, Alloc>::size_type
max_size() const noexcept
293 std::scoped_lock lk(_mutex);
294 return _queue.max_size();
300 std::scoped_lock lk(_mutex);
301 _queue.shrink_to_fit();
312 std::scoped_lock lk(_mutex);
320 typename std::deque<T>::iterator
insert(
typename std::deque<T>::const_iterator pos,
const T& value)
322 std::scoped_lock lk(_mutex);
323 return _queue.insert(pos, value);
330 typename std::deque<T>::iterator
insert(
typename std::deque<T>::const_iterator pos, T&& value)
332 std::scoped_lock lk(_mutex);
333 return _queue.insert(pos, value);
341 typename std::deque<T>::iterator
insert(
typename std::deque<T>::const_iterator pos,
typename std::deque<T, Alloc>::size_type count,
const T& value)
343 std::scoped_lock lk(_mutex);
344 return _queue.insert(pos, count, value);
353 template<
class InputIt>
354 typename std::deque<T>::iterator
insert(
typename std::deque<T>::const_iterator pos, InputIt first, InputIt last)
356 std::scoped_lock lk(_mutex);
357 return _queue.insert(pos, first, last);
364 typename std::deque<T>::iterator
insert(
typename std::deque<T>::const_iterator pos, std::initializer_list<T> ilist)
366 std::scoped_lock lk(_mutex);
367 return _queue.insert(pos, ilist);
374 template<
class... Args>
375 typename std::deque<T>::iterator
emplace(
typename std::deque<T>::const_iterator pos, Args&&... args)
377 std::scoped_lock lk(_mutex);
378 return _queue.emplace(pos, std::forward<Args>(args)...);
384 typename std::deque<T>::iterator
erase(
typename std::deque<T>::const_iterator pos)
386 std::scoped_lock lk(_mutex);
387 return _queue.erase(pos);
395 typename std::deque<T>::iterator
erase(
typename std::deque<T>::const_iterator first,
typename std::deque<T>::const_iterator last)
397 std::scoped_lock lk(_mutex);
398 return _queue.erase(first, last);
405 std::scoped_lock lk(_mutex);
406 _queue.push_back(value);
412 std::scoped_lock lk(_mutex);
413 _queue.push_back(value);
419 template<
class... Args>
422 std::scoped_lock lk(_mutex);
423 return _queue.emplace_back(std::forward<Args>(args)...);
429 std::scoped_lock lk(_mutex);
438 std::scoped_lock lk(_mutex);
439 _queue.push_front(value);
446 std::scoped_lock lk(_mutex);
447 _queue.push_front(value);
453 template<
class... Args>
456 std::scoped_lock lk(_mutex);
457 return _queue.emplace_front(std::forward<Args>(args)...);
463 std::scoped_lock lk(_mutex);
469 void resize(
typename std::deque<T, Alloc>::size_type count)
471 std::scoped_lock lk(_mutex);
472 _queue.resize(count);
477 void resize(
typename std::deque<T, Alloc>::size_type count,
const T& value)
479 std::scoped_lock lk(_mutex);
480 _queue.resize(count, value);
486 void swap(std::deque<T>& other)
noexcept
488 std::scoped_lock lk(_mutex);
498 std::scoped_lock lk(_mutex);
499 front = _queue.front();
507 std::deque<T, Alloc> _queue;
510 mutable std::mutex _mutex;
Thread-safe deque.
Definition TsDeque.hpp:27
void push_front(const T &value)
Prepends the given element value to the beginning of the container. The new element is initialized as...
Definition TsDeque.hpp:436
std::deque< T >::const_iterator begin() const noexcept
Returns an iterator to the first element of the deque. If the deque is empty, the returned iterator w...
Definition TsDeque.hpp:221
auto & emplace_back(Args &&... args)
Appends a new element to the end of the container.
Definition TsDeque.hpp:420
const auto & front() const
Returns a reference to the first element in the container.
Definition TsDeque.hpp:201
std::deque< T >::reverse_iterator rend() noexcept
Returns a reverse iterator to the element following the last element of the reversed deque....
Definition TsDeque.hpp:257
auto & back()
Returns a reference to the last element in the container.
Definition TsDeque.hpp:205
void assign(typename std::deque< T, Alloc >::size_type count, const T &value)
Replaces the contents with count copies of value value.
Definition TsDeque.hpp:138
std::deque< T >::reverse_iterator rbegin() noexcept
Returns a reverse iterator to the first element of the reversed deque. It corresponds to the last ele...
Definition TsDeque.hpp:243
TsDeque(typename std::deque< T, Alloc >::size_type count, const Alloc &alloc=Alloc())
Constructs the container with count default-inserted instances of T. No copies are made.
Definition TsDeque.hpp:54
const auto & operator[](typename std::deque< T, Alloc >::size_type pos) const
Returns a reference to the element at specified location pos. No bounds checking is performed.
Definition TsDeque.hpp:194
void resize(typename std::deque< T, Alloc >::size_type count)
Resizes the container to contain count elements.
Definition TsDeque.hpp:469
std::deque< T >::iterator insert(typename std::deque< T >::const_iterator pos, std::initializer_list< T > ilist)
Inserts elements from initializer list ilist before pos.
Definition TsDeque.hpp:364
std::deque< T >::iterator insert(typename std::deque< T >::const_iterator pos, InputIt first, InputIt last)
inserts elements from range [first, last) before pos.
Definition TsDeque.hpp:354
TsDeque(InputIt first, InputIt last, const Alloc &alloc=Alloc())
Constructs the container with the contents of the range [first, last).
Definition TsDeque.hpp:62
std::deque< T >::iterator begin() noexcept
Returns an iterator to the first element of the deque. If the deque is empty, the returned iterator w...
Definition TsDeque.hpp:217
TsDeque(TsDeque &&other) noexcept
Move constructor. Constructs the container with the contents of other using move semantics....
Definition TsDeque.hpp:84
TsDeque & operator=(std::initializer_list< T > ilist)
Replaces the contents with those identified by initializer list ilist.
Definition TsDeque.hpp:128
void resize(typename std::deque< T, Alloc >::size_type count, const T &value)
Resizes the container to contain count elements.
Definition TsDeque.hpp:477
std::deque< T >::const_reverse_iterator rbegin() const noexcept
Returns a reverse iterator to the first element of the reversed deque. It corresponds to the last ele...
Definition TsDeque.hpp:247
TsDeque & operator=(TsDeque &&other) noexcept
Move assignment operator.
Definition TsDeque.hpp:116
auto & at(typename std::deque< T, Alloc >::size_type pos)
Returns a reference to the element at specified location pos, with bounds checking....
Definition TsDeque.hpp:180
TsDeque(const Alloc &alloc)
Constructs an empty container with the given allocator alloc.
Definition TsDeque.hpp:41
void assign(std::initializer_list< T > ilist)
Replaces the contents with the elements from the initializer list ilist.
Definition TsDeque.hpp:159
void shrink_to_fit()
Requests the removal of unused capacity.
Definition TsDeque.hpp:298
void swap(std::deque< T > &other) noexcept
Exchanges the contents of the container with those of other. Does not invoke any move,...
Definition TsDeque.hpp:486
std::deque< T, Alloc >::size_type size() const noexcept
Returns the number of elements in the container, i.e. std::distance(begin(), end()).
Definition TsDeque.hpp:283
void push_front(T &&value)
Prepends the given element value to the beginning of the container. Value is moved into the new eleme...
Definition TsDeque.hpp:444
void push_back(const T &value)
Appends the given element value to the end of the container. The new element is initialized as a copy...
Definition TsDeque.hpp:403
const auto & at(typename std::deque< T, Alloc >::size_type pos) const
Returns a reference to the element at specified location pos, with bounds checking....
Definition TsDeque.hpp:185
const auto & back() const
Returns a reference to the last element in the container.
Definition TsDeque.hpp:208
std::deque< T >::const_reverse_iterator rend() const noexcept
Returns a reverse iterator to the element following the last element of the reversed deque....
Definition TsDeque.hpp:262
std::deque< T >::iterator insert(typename std::deque< T >::const_iterator pos, T &&value)
Insert value before pos in the container.
Definition TsDeque.hpp:330
void clear() noexcept
Definition TsDeque.hpp:310
~TsDeque()=default
Destructor.
void pop_back()
Removes the last element of the container.
Definition TsDeque.hpp:427
TsDeque(const TsDeque &other)
Copy constructor. Constructs the container with the copy of the contents of other.
Definition TsDeque.hpp:68
void assign(InputIt first, InputIt last)
Replaces the contents with copies of those in the range [first, last). The behavior is undefined if e...
Definition TsDeque.hpp:150
std::deque< T >::const_iterator cend() const noexcept
Returns an iterator to the element following the last element of the deque. This element acts as a pl...
Definition TsDeque.hpp:238
std::deque< T >::iterator insert(typename std::deque< T >::const_iterator pos, const T &value)
Insert value before pos in the container.
Definition TsDeque.hpp:320
TsDeque(TsDeque &&other, const Alloc &alloc) noexcept
Allocator-extended move constructor. Using alloc as the allocator for the new container,...
Definition TsDeque.hpp:93
TsDeque(typename std::deque< T, Alloc >::size_type count, const T &value, const Alloc &alloc=Alloc())
Constructs the container with count copies of elements with value value.
Definition TsDeque.hpp:48
TsDeque(std::initializer_list< T > init, const Alloc &alloc=Alloc())
Constructs the container with the contents of the initializer list init.
Definition TsDeque.hpp:101
std::deque< T >::const_reverse_iterator crbegin() const noexcept
Returns a reverse iterator to the first element of the reversed deque. It corresponds to the last ele...
Definition TsDeque.hpp:251
auto & front()
Returns a reference to the first element in the container.
Definition TsDeque.hpp:198
auto & emplace_front(Args &&... args)
Inserts a new element to the beginning of the container.
Definition TsDeque.hpp:454
std::deque< T >::iterator emplace(typename std::deque< T >::const_iterator pos, Args &&... args)
Inserts a new element into the container directly before pos.
Definition TsDeque.hpp:375
auto & operator[](typename std::deque< T, Alloc >::size_type pos)
Returns a reference to the element at specified location pos. No bounds checking is performed.
Definition TsDeque.hpp:190
std::deque< T >::iterator insert(typename std::deque< T >::const_iterator pos, typename std::deque< T, Alloc >::size_type count, const T &value)
inserts count copies of the value before pos
Definition TsDeque.hpp:341
TsDeque()=default
Default Constructor. Constructs an empty container with a default-constructed allocator.
std::deque< T >::iterator end() noexcept
Returns an iterator to the element following the last element of the deque. This element acts as a pl...
Definition TsDeque.hpp:230
auto extract_front()
Returns a copy of the first element in the container and removes it from the container.
Definition TsDeque.hpp:494
TsDeque & operator=(const TsDeque &other)
Copy assignment operator.
Definition TsDeque.hpp:105
bool empty() const noexcept
Checks if the container has no elements, i.e. whether 'begin() == end()'.
Definition TsDeque.hpp:275
std::deque< T >::iterator erase(typename std::deque< T >::const_iterator pos)
Removes the element at pos.
Definition TsDeque.hpp:384
TsDeque(const TsDeque &other, const Alloc &alloc)
Constructs the container with the copy of the contents of other, using alloc as the allocator.
Definition TsDeque.hpp:76
std::deque< T >::const_iterator end() const noexcept
Returns an iterator to the element following the last element of the deque. This element acts as a pl...
Definition TsDeque.hpp:234
std::deque< T, Alloc >::size_type max_size() const noexcept
Returns the maximum number of elements the container is able to hold due to system or library impleme...
Definition TsDeque.hpp:291
std::deque< T >::const_iterator cbegin() const noexcept
Returns an iterator to the first element of the deque. If the deque is empty, the returned iterator w...
Definition TsDeque.hpp:225
std::deque< T >::iterator erase(typename std::deque< T >::const_iterator first, typename std::deque< T >::const_iterator last)
Removes the elements in the range [first, last). All iterators and references are invalidated,...
Definition TsDeque.hpp:395
void pop_front()
Removes the first element of the container. If there are no elements in the container,...
Definition TsDeque.hpp:461
std::deque< T >::const_reverse_iterator crend() const noexcept
Returns a reverse iterator to the element following the last element of the reversed deque....
Definition TsDeque.hpp:267
std::deque< T, Alloc >::allocator_type get_allocator() const noexcept
Returns the allocator associated with the container.
Definition TsDeque.hpp:167
void push_back(T &&value)
Appends the given element value to the end of the container. Value is moved into the new element.
Definition TsDeque.hpp:410