Queue
1.0.0
A C++17 Library of various `queue` containers
|
Go to the documentation of this file.
41 #ifndef circular_queue_h__
42 #define circular_queue_h__
51 #include <initializer_list>
55 #include <type_traits>
104 template<
class T,
class Alloc = std::allocator<T>>
112 class const_iterator;
118 using allocator_type = Alloc;
119 using difference_type = ptrdiff_t;
120 using size_type = size_t;
121 using value_type = T;
123 using const_pointer =
const T*;
124 using reference = T&;
125 using const_reference =
const T&;
126 using reverse_iterator = std::reverse_iterator<iterator>;
127 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
132 queue_pointer(pointer p,
bool par)
142 const_queue_pointer(pointer p,
bool par)
162 using iterator_category = std::random_access_iterator_tag;
163 using value_type =
const T;
164 using difference_type = ptrdiff_t;
165 using pointer =
const T*;
166 using reference =
const T&;
172 friend class circular_queue;
207 const_iterator(
const const_iterator& other) =
default;
209 const_iterator& operator=(
const const_iterator& other) =
default;
211 const_iterator(const_iterator&& other)
noexcept
212 :
m_buffer(std::move(other.m_buffer))
217 const_iterator& operator=(const_iterator&& other)
noexcept
219 m_buffer = std::move(other.m_buffer);
244 return *(
this->m_pointer.ptr);
259 return this->m_pointer.ptr;
274 return this->m_pointer.ptr;
291 inline reference
operator[](difference_type n)
const
294 const_iterator tmp = *
this + n;
310 inline bool operator==(
const const_iterator& rhs)
const noexcept
313 assert(
this->m_buffer == rhs.m_buffer);
314 return ((
this->m_pointer.ptr == rhs.m_pointer.ptr) && (
this->m_pointer.parity == rhs.m_pointer.parity));
327 inline bool operator!=(
const const_iterator& rhs)
const
359 const_iterator tmp(*
this);
376 inline const_iterator&
operator+=(difference_type n)
noexcept
397 inline const_iterator
operator+(difference_type n)
const noexcept
436 const_iterator tmp(*
this);
454 inline const_iterator&
operator-=(difference_type n)
noexcept
475 inline const_iterator
operator-(difference_type n)
const
497 inline difference_type
operator-(
const const_iterator& other)
const
501 assert(
m_pointer.ptr && other.m_pointer.ptr);
503 if (
m_pointer.parity == other.m_pointer.parity)
505 return (
m_pointer.ptr - other.m_pointer.ptr);
524 inline bool operator<(
const const_iterator& rhs)
const noexcept
527 assert(
this->m_buffer == rhs.m_buffer);
534 if (
this->m_pointer.parity == rhs.m_pointer.parity)
536 return (
this->m_pointer.ptr < rhs.m_pointer.ptr);
540 return this->m_pointer.ptr > rhs.m_pointer.ptr;
555 inline bool operator<=(
const const_iterator& rhs)
const
558 return (
this->m_pointer.ptr == rhs.m_pointer.ptr ||
operator<(rhs
));
572 inline bool operator>(
const const_iterator& rhs)
const
589 inline bool operator>=(
const const_iterator& rhs)
const
613 using iterator_category = std::random_access_iterator_tag;
614 using value_type = T;
615 using difference_type = ptrdiff_t;
617 using reference = T&;
623 friend class circular_queue;
658 iterator(
const iterator& other) =
default;
659 iterator& operator=(
const iterator& other) =
default;
661 iterator(iterator&& other)
noexcept
662 : m_buffer(std::move(other.m_buffer))
667 iterator& operator=(iterator&& other)
noexcept
669 m_buffer = std::move(other.m_buffer);
680 inline ~
iterator()
noexcept =
default;
694 return *(
this->m_pointer.ptr);
709 return this->m_pointer.ptr;
724 return this->m_pointer.ptr;
741 inline reference
operator[](difference_type n)
const
744 iterator tmp = *
this + n;
760 inline bool operator==(
const iterator& rhs)
const noexcept
763 assert(
this->m_buffer == rhs.m_buffer);
764 return ((
this->m_pointer.ptr == rhs.m_pointer.ptr) && (
this->m_pointer.parity == rhs.m_pointer.parity));
827 inline iterator&
operator+=(difference_type n)
noexcept
848 inline iterator
operator+(difference_type n)
const noexcept
854 return iterator(m_buffer, p);
904 inline iterator&
operator-=(difference_type n)
noexcept
930 p = m_buffer->decrement(p, n);
932 return iterator(m_buffer, p);
947 inline difference_type
operator-(
const iterator& other)
const
950 assert(m_buffer == other.m_buffer);
951 assert(
m_pointer.ptr && other.m_pointer.ptr);
953 if (
m_pointer.parity == other.m_pointer.parity)
955 return (
m_pointer.ptr - other.m_pointer.ptr);
959 return (m_buffer->m_capacity - (other.m_pointer.ptr -
m_pointer.ptr));
974 inline bool operator<(
const iterator& rhs)
const noexcept
977 assert(
this->m_buffer == rhs.m_buffer);
984 if (
this->m_pointer.parity == rhs.m_pointer.parity)
986 return (
this->m_pointer.ptr < rhs.m_pointer.ptr);
990 return this->m_pointer.ptr > rhs.m_pointer.ptr;
1008 return (
this->m_pointer.ptr == rhs.m_pointer.ptr ||
operator<(rhs
));
1048 return const_iterator(m_buffer,
m_pointer);
1079 explicit circular_queue(size_type capacity,
const allocator_type& alloc = allocator_type())
1087 throw std::bad_alloc();
1101 throw std::bad_alloc();
1120 explicit circular_queue(size_type capacity,
const value_type& val,
const allocator_type& alloc = allocator_type())
1128 throw std::bad_alloc();
1141 throw std::bad_alloc();
1177 template<
class InputIterator>
1178 explicit circular_queue(InputIterator first, InputIterator last,
const allocator_type& alloc = allocator_type(),
typename std::enable_if<!std::is_integral<InputIterator>::value>::type* = 0)
1184 static_assert(std::is_convertible<value_type,
typename std::iterator_traits<InputIterator>::value_type>::value,
1185 "InputIterator::value_type is not compatible with this container's value_type");
1189 throw std::bad_alloc();
1202 throw std::bad_alloc();
1210 for (
auto itr = first; itr != last; ++itr)
1235 circular_queue(std::initializer_list<value_type> il,
const allocator_type& alloc = allocator_type())
1243 throw std::bad_alloc();
1256 throw std::bad_alloc();
1265 for (
auto itr = il.begin(); itr != il.end(); ++itr)
1289 :
m_alloc(std::allocator_traits<
decltype(other.m_alloc)>::select_on_container_copy_construction(other.m_alloc))
1299 m_head.ptr =
m_data + (other.m_head.ptr - other.m_data);
1300 m_tail.ptr =
m_data + (other.m_tail.ptr - other.m_data);
1303 for (const_iterator itr =
this->begin(), otherItr = other.begin(); otherItr != other.end(); ++itr, ++otherItr)
1306 std::allocator_traits<Alloc>::construct(
m_alloc, &itr, *otherItr);
1322 :
m_alloc(std::move(other.m_alloc))
1324 ,
m_head(std::move(other.m_head))
1325 ,
m_tail(std::move(other.m_tail))
1332 other.m_data =
nullptr;
1333 other.m_capacity = 0;
1334 other.m_head.ptr =
nullptr;
1335 other.m_tail.ptr =
nullptr;
1336 other.m_head.parity =
false;
1337 other.m_tail.parity =
false;
1397 if (std::allocator_traits<
decltype(other.m_alloc)>::propagate_on_container_copy_assignment::value)
1403 m_head.parity = other.m_head.parity;
1404 m_tail.parity = other.m_tail.parity;
1411 m_head.ptr =
m_data + (other.m_head.ptr - other.m_data);
1412 m_tail.ptr =
m_data + (other.m_tail.ptr - other.m_data);
1415 for (const_iterator itr =
this->begin(), otherItr = other.begin(); otherItr != other.end(); ++itr, ++otherItr)
1418 std::allocator_traits<Alloc>::construct(
m_alloc, &itr, *otherItr);
1446 if (std::allocator_traits<
decltype(other.m_alloc)>::propagate_on_container_move_assignment::value)
1448 m_alloc = std::move(other.m_alloc);
1452 m_head = std::move(other.m_head);
1453 m_tail = std::move(other.m_tail);
1459 other.m_data =
nullptr;
1460 other.m_capacity = 0;
1461 other.m_head.ptr =
nullptr;
1462 other.m_tail.ptr =
nullptr;
1463 other.m_head.parity =
false;
1464 other.m_tail.parity =
false;
1488 assign(std::forward<std::initializer_list<value_type>>(il));
1554 return iterator(
this,
m_head);
1560 return const_iterator(
this,
m_head);
1579 return iterator(
this,
m_tail);
1583 const_iterator
end()
const noexcept
1585 return const_iterator(
this,
m_tail);
1607 return reverse_iterator(end());
1611 const_reverse_iterator
rbegin()
const noexcept
1613 return const_reverse_iterator(end());
1633 return reverse_iterator(begin());
1637 const_reverse_iterator
rend()
const noexcept
1639 return const_reverse_iterator(begin());
1662 return const_iterator(
this,
m_head);
1683 const_iterator
cend()
const noexcept
1685 return const_iterator(
this,
m_tail);
1709 return const_reverse_iterator(end());
1731 const_reverse_iterator
crend()
const noexcept
1733 return const_reverse_iterator(begin());
1765 return static_cast<size_type>(
m_tail.ptr -
m_head.ptr);
1809 return std::allocator_traits<Alloc>::max_size(
m_alloc);
1904 void resize(size_type n,
const value_type& val = value_type())
1988 reference
at(size_type n)
1992 throw std::out_of_range(
"index larger than container size");
1999 const_reference
at(size_type n)
const
2003 throw std::out_of_range(
"index larger than container size");
2098 template<
class InputIterator>
2099 void assign(InputIterator first, InputIterator last)
2101 static_assert(std::is_convertible<value_type,
typename std::iterator_traits<InputIterator>::value_type>::value,
2102 "InputIterator::value_type is not compatible with this container's value_type");
2105 difference_type distance = last - first;
2108 throw std::length_error(
"Cannot assign capacity of 0");
2129 throw std::bad_alloc();
2139 for (
auto itr = first; itr != last; ++itr)
2169 void assign(size_type n,
const value_type& val)
2174 throw std::length_error(
"Cannot assign capacity of 0");
2195 throw std::bad_alloc();
2205 for (size_type i = 0; i < n; ++i)
2239 void assign(std::initializer_list<value_type> il)
2244 throw std::length_error(
"Cannot assign capacity of 0");
2265 throw std::bad_alloc();
2275 for (
auto itr = il.begin(); itr != il.end(); ++itr)
2304 for (iterator itr =
this->begin(); itr !=
this->end(); ++itr)
2306 std::allocator_traits<Alloc>::destroy(
m_alloc,
const_cast<T*>(&itr));
2345 value_type* pos =
m_head.ptr;
2352 std::allocator_traits<Alloc>::construct(
m_alloc,
m_tail.ptr, val);
2358 throw std::bad_alloc();
2375 value_type* pos =
m_head.ptr;
2377 *pos = std::move(val);
2382 std::allocator_traits<Alloc>::construct(
m_alloc,
m_tail.ptr, std::move(val));
2388 throw std::bad_alloc();
2432 std::allocator_traits<Alloc>::construct(
m_alloc,
m_head.ptr, val);
2441 throw std::bad_alloc();
2456 *
m_head.ptr = std::move(val);
2463 std::allocator_traits<Alloc>::construct(
m_alloc,
m_head.ptr, std::move(val));
2472 throw std::bad_alloc();
2549 iterator
insert(const_iterator position,
const value_type& val)
2551 assert(position.m_buffer ==
this);
2589 iterator
insert(const_iterator position, value_type&& val)
2591 assert(position.m_buffer ==
this);
2594 push_back(std::move(val));
2628 iterator
insert(const_iterator position, size_type n,
const value_type& val)
2630 assert(position.m_buffer ==
this);
2676 template<
class InputIterator>
2677 iterator
insert(const_iterator position, InputIterator first, InputIterator last)
2679 static_assert(std::is_base_of<std::forward_iterator_tag,
typename std::iterator_traits<InputIterator>::iterator_category>::value,
2680 "Insert (range) requires InputIterator to be at least a forward iterator.");
2682 static_assert(std::is_convertible<
typename std::iterator_traits<InputIterator>::value_type, value_type>::value,
2683 "InputIterator::value_type is not implicitly convertible to circular_queue::value_type.");
2685 assert(position.m_buffer ==
this);
2687 size_type n = last - first;
2689 InputIterator start = first;
2696 for (InputIterator i = std::move(start); i < last; ++i)
2734 iterator
insert(const_iterator position, std::initializer_list<value_type> il)
2736 return insert(position, il.begin(), il.end());
2765 assert(position.m_buffer ==
this);
2771 return iterator(
this, position.m_pointer);
2800 iterator
erase(const_iterator first, const_iterator last)
2802 assert(first.m_buffer ==
this);
2803 assert(last.m_buffer ==
this);
2804 assert(last > first);
2806 difference_type n = last - first;
2810 for (difference_type i = 0; i < n; ++i)
2815 return iterator(
this, first.m_pointer);
2842 if (std::allocator_traits<
decltype(other.m_alloc)>::propagate_on_container_swap::value)
2844 allocator_type temp =
this->m_alloc;
2845 this->m_alloc = other.m_alloc;
2846 other.m_alloc = temp;
2849 auto tempData =
this->m_data;
2850 this->m_data = other.m_data;
2851 other.m_data = tempData;
2853 auto tempCapacity =
this->m_capacity;
2854 this->m_capacity = other.m_capacity;
2855 other.m_capacity = tempCapacity;
2857 auto tempHead =
this->m_head;
2858 this->m_head = other.m_head;
2859 other.m_head = tempHead;
2861 auto tempTail =
this->m_tail;
2862 this->m_tail = other.m_tail;
2863 other.m_tail = tempTail;
2891 template<
class... Args>
2892 iterator
emplace(const_iterator position, Args&&... args)
2894 assert(position.m_buffer ==
this);
2897 emplace_back(std::forward<Args>(args)...);
2923 template<
class... Args>
2938 std::allocator_traits<Alloc>::construct(
m_alloc,
m_head.ptr, std::forward<Args>(args)...);
2946 throw std::bad_alloc();
2971 template<
class... Args>
2984 std::allocator_traits<Alloc>::construct(
m_alloc,
m_tail.ptr, std::forward<Args>(args)...);
2992 throw std::bad_alloc();
3042 template<
class copyFunctor>
3043 auto copy(const_iterator first, const_iterator last, value_type* destination, copyFunctor cf)
const ->
decltype(cf((
void*) destination, (
void*) first.m_pointer.ptr, ((last.m_pointer.ptr - first.m_pointer.ptr) *
sizeof(value_type))))
3046 if (first.m_pointer.parity == last.m_pointer.parity)
3049 return cf((
void*) destination, (
void*) first.m_pointer.ptr, ((last.m_pointer.ptr - first.m_pointer.ptr) *
sizeof(value_type)));
3056 cf((
void*) destination, (
void*) first.m_pointer.ptr, firstChunkSize *
sizeof(value_type));
3057 return cf(destination + firstChunkSize, (
void*)
m_data, (last.m_pointer.ptr -
m_data) *
sizeof(value_type));
3081 if (p.ptr >=
this->m_data +
this->m_capacity)
3085 p.parity = !p.parity;
3093 p.parity = !p.parity;
3110 p.parity = !p.parity;
3118 p.parity = !p.parity;
3142 p.parity = !p.parity;
3150 p.parity = !p.parity;
3167 p.parity = !p.parity;
3175 p.parity = !p.parity;
3194 newData = newDataItr = std::allocator_traits<Alloc>::allocate(
m_alloc, n,
this);
3198 throw std::bad_alloc();
3205 for (
auto&& front : *
this)
3207 std::allocator_traits<Alloc>::construct(
m_alloc, newDataItr, std::move(front));
3218 pointer newDataDestroyer = newData;
3219 while (newDataDestroyer < newDataItr)
3221 std::allocator_traits<Alloc>::destroy(
m_alloc, newDataDestroyer);
3224 m_alloc.deallocate(newData, n);
3239 difference_type distance = newDataItr - newData;
3240 for (difference_type diff = 0; diff < distance; ++diff)
3253 inline iterator
swapDownTo(const_iterator position, size_type n)
noexcept
3256 iterator pos(
this,
const_cast<value_type*>(position.m_pointer.ptr), position.m_pointer.parity);
3259 pos = pos > begin() ? pos : begin();
3261 if (pos == end() - n)
return pos;
3264 for (size_type i = 0; i < n; ++i)
3266 for (iterator swapItr = --end(); swapItr != pos; --swapItr)
3269 auto temp = std::move(*swapItr);
3270 *swapItr = std::move(*(swapItr - 1));
3271 *(swapItr - 1) = std::move(temp);
3285 inline iterator
swapUpToEnd(const_iterator position, size_type n)
noexcept
3288 iterator pos(
this,
const_cast<pointer>(position.m_pointer.ptr), position.m_pointer.parity);
3291 pos = pos > begin() ? pos : begin();
3293 if (pos == end() - n)
return pos;
3296 for (size_type i = 0; i < n; ++i)
3298 for (iterator swapItr = pos; swapItr != end() - 1; ++swapItr)
3301 auto temp = std::move(*swapItr);
3302 *swapItr = std::move(*(swapItr + 1));
3303 *(swapItr + 1) = std::move(temp);
void shrink_to_fit()
Shrink container to fit.
Definition: circular_queue.h:1948
bool operator<=(const const_iterator &rhs) const
less-than-or-equal operator
Definition: circular_queue.h:555
const circular_queue * m_buffer
pointer to the buffer object that this iterates on.
Definition: circular_queue.h:596
pointer operator->() const
Dereference operator.
Definition: circular_queue.h:271
iterator & operator+=(difference_type n) noexcept
Advance iterator.
Definition: circular_queue.h:827
queue_pointer decrement(queue_pointer p, difference_type n) const noexcept
decrements a pointer
Definition: circular_queue.h:3133
const_reference operator[](size_type n) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: circular_queue.h:1520
void assign(std::initializer_list< value_type > il)
Assign container contents from initializer list.
Definition: circular_queue.h:2239
iterator erase(const_iterator first, const_iterator last)
Erase elements.
Definition: circular_queue.h:2800
bool operator>=(const const_iterator &rhs) const
greater-than-or-equal operator
Definition: circular_queue.h:589
size_type max_size() const noexcept
Return maximum capacity.
Definition: circular_queue.h:1807
bool operator==(const iterator &rhs) const noexcept
equality operator
Definition: circular_queue.h:760
reference operator[](size_type n)
Access element.
Definition: circular_queue.h:1513
pointer operator&() const
Dereference operator.
Definition: circular_queue.h:256
bool operator>(const const_iterator &rhs) const
greater-than operator
Definition: circular_queue.h:572
circular_queue(std::initializer_list< value_type > il, const allocator_type &alloc=allocator_type())
construct from initializer list
Definition: circular_queue.h:1235
circular_queue & operator=(const circular_queue &other)
Assign content.
Definition: circular_queue.h:1392
const_reverse_iterator crbegin() const noexcept
Returns constant iterator to beginning.
Definition: circular_queue.h:1707
iterator & operator-=(difference_type n) noexcept
Retrocede iterator.
Definition: circular_queue.h:904
void reallocate(size_type n)
moves the currently contained data to a new area with size n.
Definition: circular_queue.h:3187
difference_type operator-(const const_iterator &other) const
subtraction operator
Definition: circular_queue.h:497
iterator insert(const_iterator position, value_type &&val)
Insert (move) single element.
Definition: circular_queue.h:2589
queue_pointer m_tail
Points to the logical end of the buffer. No memory ownership!
Definition: circular_queue.h:3315
bool operator>=(const iterator &rhs) const
greater-than-or-equal operator
Definition: circular_queue.h:1039
bool empty() const noexcept
Test whether container is empty.
Definition: circular_queue.h:1822
operator const_iterator() const
Allow implicit conversion from iterator to const_iterator as required by STL.
Definition: circular_queue.h:1046
const_reverse_iterator crend() const noexcept
Returns constant iterator to end.
Definition: circular_queue.h:1731
const_reference front() const noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: circular_queue.h:2032
~const_iterator() noexcept=default
destructor. Complexity: Constant. Exception Safety: No-throw guarantee: This function never throws...
size_type size() const noexcept
Return size.
Definition: circular_queue.h:1760
auto copy(const_iterator first, const_iterator last, value_type *destination, copyFunctor cf) const -> decltype(cf((void *) destination,(void *) first.m_pointer.ptr,((last.m_pointer.ptr - first.m_pointer.ptr) *sizeof(value_type))))
Copies range to destination buffer using provided copy function.
Definition: circular_queue.h:3043
bool operator!=(const const_iterator &rhs) const
inequality operator Complexity: Constant. Iterator Validity: No changes. Data Races: The contain...
Definition: circular_queue.h:327
bool operator>(const iterator &rhs) const
greater-than operator
Definition: circular_queue.h:1022
void pop_front() noexcept
Delete first element.
Definition: circular_queue.h:2514
void push_front(value_type &&val)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: circular_queue.h:2446
queue_pointer increment(queue_pointer p, difference_type n) const noexcept
increments a pointer
Definition: circular_queue.h:3076
const_iterator cend() const noexcept
Returns constant iterator to end.
Definition: circular_queue.h:1683
reference front() noexcept
Access first element.
Definition: circular_queue.h:2026
const_iterator operator++(int)
Increment iterator position (postfix)
Definition: circular_queue.h:357
const_iterator end() const noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: circular_queue.h:1583
constant pointer with parity
Definition: circular_queue.h:140
pointer operator&() const
Dereference operator.
Definition: circular_queue.h:706
iterator begin() noexcept
Returns iterator to beginning.
Definition: circular_queue.h:1552
pointer operator->() const
Dereference operator.
Definition: circular_queue.h:721
circular_queue(const circular_queue &other)
Copy Constructor.
Definition: circular_queue.h:1288
bool operator<(const iterator &rhs) const noexcept
less-than operator
Definition: circular_queue.h:974
iterator operator--(int)
Decrease iterator position (postfix)
Definition: circular_queue.h:884
iterator insert(const_iterator position, InputIterator first, InputIterator last)
Insert (range) elements.
Definition: circular_queue.h:2677
iterator insert(const_iterator position, const value_type &val)
Insert (copy) single element.
Definition: circular_queue.h:2549
void clear() noexcept
Clear content.
Definition: circular_queue.h:2301
reference operator[](difference_type n) const
Dereference iterator with offset.
Definition: circular_queue.h:291
Fixed capacity, STL-style, templated circular buffer.
Definition: circular_queue.h:105
circular_queue(size_type capacity, const allocator_type &alloc=allocator_type())
Constructor.
Definition: circular_queue.h:1079
iterator & operator++() noexcept
Increment iterator position (prefix)
Definition: circular_queue.h:793
const_iterator operator+(difference_type n) const noexcept
Addition operator.
Definition: circular_queue.h:397
const_queue_pointer decrement(const_queue_pointer p, difference_type n, bool &parity) const noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: circular_queue.h:3158
~iterator() noexcept=default
destructor. Complexity: Constant. Exception Safety: No-throw guarantee: This function never throws...
const_reference at(size_type n) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: circular_queue.h:1999
reference operator*() const
Dereference operator.
Definition: circular_queue.h:241
pointer with parity
Definition: circular_queue.h:130
iterator emplace(const_iterator position, Args &&... args)
Construct and insert element.
Definition: circular_queue.h:2892
allocator_type get_allocator() const noexcept
Get allocator.
Definition: circular_queue.h:3020
reference back()
Access last element.
Definition: circular_queue.h:2054
const_reverse_iterator rend() const noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: circular_queue.h:1637
reverse_iterator rbegin() noexcept
Returns reverse iterator to beginning.
Definition: circular_queue.h:1605
const_queue_pointer increment(const_queue_pointer p, difference_type n) const noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: circular_queue.h:3101
iterator swapUpToEnd(const_iterator position, size_type n) noexcept
Moves the given position to the end of the queue by successively swapping it.
Definition: circular_queue.h:3285
void swap(circular_queue &other) noexcept
Swap content.
Definition: circular_queue.h:2840
difference_type operator-(const iterator &other) const
subtraction operator
Definition: circular_queue.h:947
circular_queue(InputIterator first, InputIterator last, const allocator_type &alloc=allocator_type(), typename std::enable_if<!std::is_integral< InputIterator >::value >::type *=0)
Range Constructor.
Definition: circular_queue.h:1178
const_iterator operator--(int)
Decrease iterator position (postfix)
Definition: circular_queue.h:434
void emplace_front(Args &&... args)
Construct and insert element at beginning.
Definition: circular_queue.h:2924
iterator operator-(difference_type n) const
subtraction operator
Definition: circular_queue.h:925
bool operator<(const const_iterator &rhs) const noexcept
less-than operator
Definition: circular_queue.h:524
iterator insert(const_iterator position, size_type n, const value_type &val)
Insert (fill) elements.
Definition: circular_queue.h:2628
circular_queue & operator=(circular_queue &&other) noexcept
Assign content.
Definition: circular_queue.h:1441
void assign(InputIterator first, InputIterator last)
Assign container content range.
Definition: circular_queue.h:2099
bool operator==(const const_iterator &rhs) const noexcept
equality operator
Definition: circular_queue.h:310
iterator(const circular_queue *const buffer, pointer start, bool parity) noexcept
Constructor.
Definition: circular_queue.h:640
void pop_back() noexcept
Delete last element.
Definition: circular_queue.h:2492
iterator insert(const_iterator position, std::initializer_list< value_type > il)
Insert elements (initializer_list)
Definition: circular_queue.h:2734
iterator operator+(difference_type n) const noexcept
Addition operator.
Definition: circular_queue.h:848
iterator swapDownTo(const_iterator position, size_type n) noexcept
Swaps the back of the queue down to position with elements n positions away.
Definition: circular_queue.h:3253
size_type m_capacity
capacity of the buffer array.
Definition: circular_queue.h:3313
const_iterator & operator++() noexcept
Increment iterator position (prefix)
Definition: circular_queue.h:342
reference operator*() const
Dereference operator.
Definition: circular_queue.h:691
bool operator<=(const iterator &rhs) const
less-than-or-equal operator
Definition: circular_queue.h:1005
bool operator!=(const iterator &rhs) const
inequality operator Complexity: Constant. Iterator Validity: No changes. Data Races: The contain...
Definition: circular_queue.h:777
circular_queue & operator=(std::initializer_list< value_type > il)
Assign content.
Definition: circular_queue.h:1486
queue_pointer m_pointer
Iterator position.
Definition: circular_queue.h:597
pointer m_data
Pointer to the internal data array.
Definition: circular_queue.h:3312
Alloc m_alloc
Allocator class. NOT c-style malloc.
Definition: circular_queue.h:3311
const_iterator(const circular_queue *buffer, pointer start, bool parity) noexcept
Constructor.
Definition: circular_queue.h:189
iterator operator++(int)
Increment iterator position (postfix)
Definition: circular_queue.h:808
reference operator[](difference_type n) const
Dereference iterator with offset.
Definition: circular_queue.h:741
bool full() const noexcept
Test whether container is full.
Definition: circular_queue.h:1836
reverse_iterator rend() noexcept
Returns reverse iterator to end.
Definition: circular_queue.h:1631
queue_pointer m_pointer
Iterator position.
Definition: circular_queue.h:1053
const_iterator cbegin() const noexcept
Returns constant iterator to beginning.
Definition: circular_queue.h:1660
const_iterator & operator+=(difference_type n) noexcept
Advance iterator.
Definition: circular_queue.h:376
size_type capacity() const noexcept
Get buffer capacity.
Definition: circular_queue.h:1786
const_iterator & operator--() noexcept
Decrease iterator position (prefix)
Definition: circular_queue.h:418
const_iterator & operator-=(difference_type n) noexcept
Retrocede iterator.
Definition: circular_queue.h:454
iterator & operator--() noexcept
Decrease iterator position (prefix)
Definition: circular_queue.h:868
void assign(size_type n, const value_type &val)
Assign container content by fill.
Definition: circular_queue.h:2169
reference at(size_type n)
Access element.
Definition: circular_queue.h:1988
const_iterator begin() const noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: circular_queue.h:1558
void push_front(const value_type &val)
Add element at beginning.
Definition: circular_queue.h:2415
void push_back(const value_type &val)
Add element at the end.
Definition: circular_queue.h:2336
const_iterator operator-(difference_type n) const
subtraction operator
Definition: circular_queue.h:475
void emplace_back(Args &&... args)
Construct and insert element at the end.
Definition: circular_queue.h:2972
const_reverse_iterator rbegin() const noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: circular_queue.h:1611
void resize(size_type n, const value_type &val=value_type())
Change size.
Definition: circular_queue.h:1904
circular_queue(size_type capacity, const value_type &val, const allocator_type &alloc=allocator_type())
fill constructor
Definition: circular_queue.h:1120
queue_pointer m_head
Points to the logical beginning of the buffer. No memory ownership!
Definition: circular_queue.h:3314
iterator erase(const_iterator position)
Erase element.
Definition: circular_queue.h:2763
virtual ~circular_queue()
destructor
Definition: circular_queue.h:1356
circular_queue(circular_queue &&other) noexcept
move constructor
Definition: circular_queue.h:1321
void push_back(value_type &&val)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: circular_queue.h:2366
iterator end() noexcept
Returns iterator to end.
Definition: circular_queue.h:1577
void reserve(size_type n)
Request a change in capacity.
Definition: circular_queue.h:1863
const_reference back() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: circular_queue.h:2061