1#ifndef CONTAINER_PREALLOCATED_DEQUE_H_INCLUDED
2#define CONTAINER_PREALLOCATED_DEQUE_H_INCLUDED
5#ifndef CPPELIB_NO_STD_ITERATOR
9#include "private/TypeTraits.h"
10#include "private/Construct.h"
16class PreallocatedDeque;
21template <
typename T,
typename Ref,
typename Ptr,
typename DeqPtr>
33#ifndef CPPELIB_NO_STD_ITERATOR
56 m_idx = m_deq->next_idx(m_idx, un);
74 m_idx = m_deq->prev_idx(m_idx, un);
83 return static_cast<difference_type>(m_deq->distance_idx(x.m_idx, m_idx));
85 return -
static_cast<difference_type>(m_deq->distance_idx(m_idx, x.m_idx));
121 return m_deq->m_buf[m_idx];
127 return &m_deq->m_buf[m_idx];
137 return (m_deq == x.m_deq) && (m_idx == x.m_idx);
142 return !(*
this == x);
150 m_deq->distance_idx(m_deq->m_begin, m_idx) <
151 m_deq->distance_idx(x.m_deq->m_begin, x.m_idx);
170 template <
typename U>
173 template <
typename U,
typename RefX,
typename PtrX,
typename DeqPtrX>
182template <
typename T,
typename Ref,
typename Ptr,
typename DeqPtr>
183PreallocatedDeque_iterator<T, Ref, Ptr, DeqPtr>
211#ifndef CPPELIB_NO_STD_ITERATOR
227 return "PreallocatedDeque::BadAlloc";
239 : m_buf(0), m_buf_size(0
U), m_begin(0
U), m_end(0
U)
289 return distance_idx(m_begin, m_end);
294 return (m_buf_size /
sizeof(
T)) - 1U;
304 return m_begin == m_end;
364#ifndef CPPELIB_NO_STD_ITERATOR
414 m_end = prev_idx(m_end,
size() -
n);
432 construct(&*
end(), data);
433 m_end = next_idx(m_end);
439 destroy(&*(
end() - 1));
440 m_end = prev_idx(m_end);
448 construct(&*(
begin() - 1), data);
449 m_begin = prev_idx(m_begin);
456 m_begin = next_idx(m_begin);
468 template <
typename InputIterator>
487 return insert_n(
pos, 1U, data);
493 insert_n(
pos,
n, data);
496 template <
typename InputIterator>
522 m_end = prev_idx(m_end,
n);
531 m_begin = next_idx(m_begin,
n);
537 template <
typename U,
typename Ref,
typename Ptr,
typename DeqPtr>
540 template <
typename U>
545 return m_buf_size /
sizeof(
T);
550 if (
idx +
un < num_elems_in_buf()) {
554 return idx +
un - num_elems_in_buf();
563 return num_elems_in_buf() +
idx -
un;
575 template <
typename Integer>
581 template <
typename InputIterator>
600 m_end = next_idx(m_end);
610 construct(&*
end(), data);
611 m_end = next_idx(m_end);
614 construct(&*
end(), *
it);
615 m_end = next_idx(m_end);
628 construct(&*(
begin() - 1));
629 m_begin = prev_idx(m_begin);
639 construct(&*(
begin() - 1), data);
640 m_begin = prev_idx(m_begin);
643 construct(&*(
begin() - 1), *
it);
644 m_begin = prev_idx(m_begin);
654 template <
typename InputIterator>
672 m_end = next_idx(m_end);
688 m_end = next_idx(m_end);
691 construct(&*
end(), *
it);
692 m_end = next_idx(m_end);
704 construct(&*(
begin() - 1));
705 m_begin = prev_idx(m_begin);
720 construct(&*(
begin() - 1), *--
p);
721 m_begin = prev_idx(m_begin);
724 construct(&*(
begin() - 1), *
it);
725 m_begin = prev_idx(m_begin);
745 for (std::size_t i = 0U; i < x.
size(); ++i) {
746 if (!(x[i] == y[i])) {
#define DEBUG_ASSERT(x)
The same as CHECK_ASSERT() macro.
Definition Assertion.h:39
Definition ContainerException.h:34
Definition ContainerException.h:23
Random-access iterator used as PreallocatedDeque<T>::iterator or PreallocatedDeque<T>::const_iterator...
Definition PreallocatedDeque.h:22
PreallocatedDeque_iterator operator--(int)
Definition PreallocatedDeque.h:111
Ref reference
Definition PreallocatedDeque.h:29
bool operator>(const PreallocatedDeque_iterator &x) const
Definition PreallocatedDeque.h:154
Ptr pointer
Definition PreallocatedDeque.h:31
PreallocatedDeque_iterator operator+(difference_type n) const
Definition PreallocatedDeque.h:60
const Ref const_reference
Definition PreallocatedDeque.h:30
friend class PreallocatedDeque_iterator
Definition PreallocatedDeque.h:174
PreallocatedDeque_iterator & operator=(const iterator &x)
Definition PreallocatedDeque.h:41
PreallocatedDeque_iterator & operator+=(difference_type n)
Definition PreallocatedDeque.h:48
PreallocatedDeque_iterator operator-(difference_type n) const
Definition PreallocatedDeque.h:88
PreallocatedDeque_iterator(const iterator &x)
Definition PreallocatedDeque.h:39
bool operator<=(const PreallocatedDeque_iterator &x) const
Definition PreallocatedDeque.h:159
bool operator>=(const PreallocatedDeque_iterator &x) const
Definition PreallocatedDeque.h:164
const Ptr const_pointer
Definition PreallocatedDeque.h:32
PreallocatedDeque_iterator()
Definition PreallocatedDeque.h:37
pointer operator->() const
Definition PreallocatedDeque.h:124
difference_type operator-(const PreallocatedDeque_iterator &x) const
Definition PreallocatedDeque.h:78
reference operator[](difference_type n) const
Definition PreallocatedDeque.h:130
PreallocatedDeque_iterator & operator-=(difference_type n)
Definition PreallocatedDeque.h:66
std::ptrdiff_t difference_type
Definition PreallocatedDeque.h:26
PreallocatedDeque_iterator & operator++()
Definition PreallocatedDeque.h:94
PreallocatedDeque_iterator & operator--()
Definition PreallocatedDeque.h:99
bool operator!=(const PreallocatedDeque_iterator &x) const
Definition PreallocatedDeque.h:140
bool operator<(const PreallocatedDeque_iterator &x) const
Definition PreallocatedDeque.h:145
std::size_t size_type
Definition PreallocatedDeque.h:25
reference operator*() const
Definition PreallocatedDeque.h:118
PreallocatedDeque_iterator< T, const T &, const T *, const PreallocatedDeque< T > * > const_iterator
Definition PreallocatedDeque.h:28
bool operator==(const PreallocatedDeque_iterator &x) const
Definition PreallocatedDeque.h:135
PreallocatedDeque_iterator< T, T &, T *, PreallocatedDeque< T > * > iterator
Definition PreallocatedDeque.h:27
T value_type
Definition PreallocatedDeque.h:24
PreallocatedDeque_iterator operator++(int)
Definition PreallocatedDeque.h:104
std::random_access_iterator_tag iterator_category
Definition PreallocatedDeque.h:34
STL-like deque container using pre-allocated buffer.
Definition PreallocatedDeque.h:200
T value_type
Definition PreallocatedDeque.h:202
const value_type & const_reference
Definition PreallocatedDeque.h:208
PreallocatedDeque_iterator< T, const T &, const T *, const PreallocatedDeque * > const_iterator
Definition PreallocatedDeque.h:206
size_type available_size() const
Definition PreallocatedDeque.h:297
reverse_iterator rend()
Definition PreallocatedDeque.h:375
void assign(size_type n, const T &data)
Definition PreallocatedDeque.h:459
void resize(size_type n, const T &data=T())
Definition PreallocatedDeque.h:410
const value_type * const_pointer
Definition PreallocatedDeque.h:210
iterator erase(iterator first, iterator last)
Definition PreallocatedDeque.h:510
const_iterator begin() const
Definition PreallocatedDeque.h:349
PreallocatedDeque & operator=(const PreallocatedDeque &x)
Definition PreallocatedDeque.h:279
void insert(iterator pos, InputIterator first, InputIterator last)
Definition PreallocatedDeque.h:497
bool full() const
Definition PreallocatedDeque.h:307
void push_front(const T &data)
Definition PreallocatedDeque.h:443
const_reference back() const
Definition PreallocatedDeque.h:404
friend bool operator==(const PreallocatedDeque< U > &x, const PreallocatedDeque< U > &y)
reverse_iterator rbegin()
Definition PreallocatedDeque.h:365
std::reverse_iterator< iterator > reverse_iterator
Definition PreallocatedDeque.h:212
iterator begin()
Definition PreallocatedDeque.h:344
void push_back(const T &data)
Definition PreallocatedDeque.h:427
std::ptrdiff_t difference_type
Definition PreallocatedDeque.h:204
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition PreallocatedDeque.h:213
size_type max_size() const
Definition PreallocatedDeque.h:292
void pop_back()
Definition PreallocatedDeque.h:436
PreallocatedDeque_iterator< T, T &, T *, PreallocatedDeque * > iterator
Definition PreallocatedDeque.h:205
value_type * pointer
Definition PreallocatedDeque.h:209
const_reverse_iterator rbegin() const
Definition PreallocatedDeque.h:370
void assign(InputIterator first, InputIterator last)
Definition PreallocatedDeque.h:469
const_reference operator[](size_type idx) const
Definition PreallocatedDeque.h:323
iterator erase(iterator pos)
Definition PreallocatedDeque.h:504
const_reference front() const
Definition PreallocatedDeque.h:392
~PreallocatedDeque()
Destructor.
Definition PreallocatedDeque.h:257
iterator insert(iterator pos, const T &data)
Definition PreallocatedDeque.h:484
size_type size() const
Definition PreallocatedDeque.h:287
std::size_t size_type
Definition PreallocatedDeque.h:203
const_reference at(size_type idx) const
Definition PreallocatedDeque.h:336
reference front()
Definition PreallocatedDeque.h:386
reference at(size_type idx)
Definition PreallocatedDeque.h:328
const_reverse_iterator rend() const
Definition PreallocatedDeque.h:380
bool empty() const
Definition PreallocatedDeque.h:302
iterator end()
Definition PreallocatedDeque.h:354
void init(void *preallocated_buffer, size_type buffer_size)
Initialize.
Definition PreallocatedDeque.h:270
reference back()
Definition PreallocatedDeque.h:398
PreallocatedDeque(void *preallocated_buffer, size_type buffer_size)
Constructor.
Definition PreallocatedDeque.h:248
value_type & reference
Definition PreallocatedDeque.h:207
void clear()
Definition PreallocatedDeque.h:312
void insert(iterator pos, size_type n, const T &data)
Definition PreallocatedDeque.h:490
reference operator[](size_type idx)
Definition PreallocatedDeque.h:318
void pop_front()
Definition PreallocatedDeque.h:452
PreallocatedDeque()
Default constructor.
Definition PreallocatedDeque.h:238
const_iterator end() const
Definition PreallocatedDeque.h:359
FixedDeque_iterator< T, Ref, Ptr, DeqPtr, MaxSize > operator+(std::ptrdiff_t n, const FixedDeque_iterator< T, Ref, Ptr, DeqPtr, MaxSize > &x)
Definition FixedDeque.h:184
bool operator==(const Array< T, Size > &x, const Array< T, Size > &y)
Definition Array.h:160
bool operator!=(const Array< T, Size > &x, const Array< T, Size > &y)
Definition Array.h:171