1#ifndef CONTAINER_FIXED_DEQUE_H_INCLUDED
2#define CONTAINER_FIXED_DEQUE_H_INCLUDED
5#ifndef CPPELIB_NO_STD_ITERATOR
9#include "private/TypeTraits.h"
10#include "private/Construct.h"
15template <
typename T, std::
size_t MaxSize>
21template <
typename T,
typename Ref,
typename Ptr,
typename DeqPtr, std::
size_t MaxSize>
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_virtualBuf[m_idx];
127 return &m_deq->m_virtualBuf[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, std::
size_t N>
173 template <
typename U,
typename RefX,
typename PtrX,
typename DeqPtrX, std::
size_t N>
182template <
typename T,
typename Ref,
typename Ptr,
typename DeqPtr, std::
size_t MaxSize>
183FixedDeque_iterator<T, Ref, Ptr, DeqPtr, MaxSize>
200template <
typename T, std::
size_t MaxSize>
212#ifndef CPPELIB_NO_STD_ITERATOR
221 double dummyForAlignment;
222 char buf[
sizeof(
T) * BufSize];
224 InternalBuf m_realBuf;
225 T (&m_virtualBuf)[BufSize];
234 return "FixedDeque::BadAlloc";
240 : m_realBuf(), m_virtualBuf(*
reinterpret_cast<
T(*)[BufSize]>(&m_realBuf)), m_begin(0
U), m_end(0
U)
244 : m_realBuf(), m_virtualBuf(*
reinterpret_cast<
T(*)[BufSize]>(&m_realBuf)), m_begin(0
U), m_end(0
U)
249 template <
typename InputIterator>
251 : m_realBuf(), m_virtualBuf(*
reinterpret_cast<
T(*)[BufSize]>(&m_realBuf)), m_begin(0
U), m_end(0
U)
257 : m_realBuf(), m_virtualBuf(*
reinterpret_cast<
T(*)[BufSize]>(&m_realBuf)), m_begin(0
U), m_end(0
U)
277 return distance_idx(m_begin, m_end);
292 return m_begin == m_end;
352#ifndef CPPELIB_NO_STD_ITERATOR
402 m_end = prev_idx(m_end,
size() -
n);
420 construct(&*
end(), data);
421 m_end = next_idx(m_end);
427 destroy(&*(
end() - 1));
428 m_end = prev_idx(m_end);
436 construct(&*(
begin() - 1), data);
437 m_begin = prev_idx(m_begin);
444 m_begin = next_idx(m_begin);
456 template <
typename InputIterator>
475 return insert_n(
pos, 1U, data);
481 insert_n(
pos,
n, data);
484 template <
typename InputIterator>
510 m_end = prev_idx(m_end,
n);
519 m_begin = next_idx(m_begin,
n);
525 template <
typename U,
typename Ref,
typename Ptr,
typename DeqPtr, std::
size_t N>
528 template <
typename U, std::
size_t N>
533 if (
idx +
un < BufSize) {
537 return idx +
un - BufSize;
546 return BufSize +
idx -
un;
558 template <
typename Integer>
564 template <
typename InputIterator>
583 m_end = next_idx(m_end);
593 construct(&*
end(), data);
594 m_end = next_idx(m_end);
597 construct(&*
end(), *
it);
598 m_end = next_idx(m_end);
611 construct(&*(
begin() - 1));
612 m_begin = prev_idx(m_begin);
622 construct(&*(
begin() - 1), data);
623 m_begin = prev_idx(m_begin);
626 construct(&*(
begin() - 1), *
it);
627 m_begin = prev_idx(m_begin);
637 template <
typename InputIterator>
655 m_end = next_idx(m_end);
671 m_end = next_idx(m_end);
674 construct(&*
end(), *
it);
675 m_end = next_idx(m_end);
687 construct(&*(
begin() - 1));
688 m_begin = prev_idx(m_begin);
703 construct(&*(
begin() - 1), *--
p);
704 m_begin = prev_idx(m_begin);
707 construct(&*(
begin() - 1), *
it);
708 m_begin = prev_idx(m_begin);
719template <
typename T, std::
size_t MaxSize>
725 for (std::size_t i = 0U; i < x.
size(); ++i) {
726 if (!(x[i] == y[i])) {
733template <
typename T, std::
size_t MaxSize>
#define DEBUG_ASSERT(x)
The same as CHECK_ASSERT() macro.
Definition Assertion.h:39
Definition ContainerException.h:34
Random-access iterator used as FixedDeque<T, MaxSize>::iterator or FixedDeque<T, MaxSize>::const_iter...
Definition FixedDeque.h:22
bool operator>=(const FixedDeque_iterator &x) const
Definition FixedDeque.h:164
FixedDeque_iterator operator--(int)
Definition FixedDeque.h:111
const Ref const_reference
Definition FixedDeque.h:30
reference operator*() const
Definition FixedDeque.h:118
bool operator<(const FixedDeque_iterator &x) const
Definition FixedDeque.h:145
bool operator!=(const FixedDeque_iterator &x) const
Definition FixedDeque.h:140
FixedDeque_iterator & operator--()
Definition FixedDeque.h:99
pointer operator->() const
Definition FixedDeque.h:124
reference operator[](difference_type n) const
Definition FixedDeque.h:130
const Ptr const_pointer
Definition FixedDeque.h:32
difference_type operator-(const FixedDeque_iterator &x) const
Definition FixedDeque.h:78
bool operator==(const FixedDeque_iterator &x) const
Definition FixedDeque.h:135
Ref reference
Definition FixedDeque.h:29
FixedDeque_iterator & operator-=(difference_type n)
Definition FixedDeque.h:66
FixedDeque_iterator & operator=(const iterator &x)
Definition FixedDeque.h:41
FixedDeque_iterator< T, T &, T *, FixedDeque< T, MaxSize > *, MaxSize > iterator
Definition FixedDeque.h:27
FixedDeque_iterator operator+(difference_type n) const
Definition FixedDeque.h:60
FixedDeque_iterator & operator++()
Definition FixedDeque.h:94
FixedDeque_iterator operator++(int)
Definition FixedDeque.h:104
FixedDeque_iterator & operator+=(difference_type n)
Definition FixedDeque.h:48
friend class FixedDeque_iterator
Definition FixedDeque.h:174
FixedDeque_iterator operator-(difference_type n) const
Definition FixedDeque.h:88
FixedDeque_iterator(const iterator &x)
Definition FixedDeque.h:39
T value_type
Definition FixedDeque.h:24
std::size_t size_type
Definition FixedDeque.h:25
Ptr pointer
Definition FixedDeque.h:31
FixedDeque_iterator< T, const T &, const T *, const FixedDeque< T, MaxSize > *, MaxSize > const_iterator
Definition FixedDeque.h:28
std::random_access_iterator_tag iterator_category
Definition FixedDeque.h:34
bool operator>(const FixedDeque_iterator &x) const
Definition FixedDeque.h:154
FixedDeque_iterator()
Definition FixedDeque.h:37
bool operator<=(const FixedDeque_iterator &x) const
Definition FixedDeque.h:159
std::ptrdiff_t difference_type
Definition FixedDeque.h:26
STL-like deque container with fixed capacity.
Definition FixedDeque.h:201
void insert(iterator pos, InputIterator first, InputIterator last)
Definition FixedDeque.h:485
value_type & reference
Definition FixedDeque.h:208
void clear()
Definition FixedDeque.h:300
void push_back(const T &data)
Definition FixedDeque.h:415
size_type max_size() const
Definition FixedDeque.h:280
std::reverse_iterator< iterator > reverse_iterator
Definition FixedDeque.h:213
const_reference operator[](size_type idx) const
Definition FixedDeque.h:311
std::size_t size_type
Definition FixedDeque.h:204
const value_type * const_pointer
Definition FixedDeque.h:211
FixedDeque(InputIterator first, InputIterator last)
Definition FixedDeque.h:250
size_type available_size() const
Definition FixedDeque.h:285
void insert(iterator pos, size_type n, const T &data)
Definition FixedDeque.h:478
const_reverse_iterator rend() const
Definition FixedDeque.h:368
const_iterator begin() const
Definition FixedDeque.h:337
void assign(InputIterator first, InputIterator last)
Definition FixedDeque.h:457
iterator erase(iterator pos)
Definition FixedDeque.h:492
const_reference back() const
Definition FixedDeque.h:392
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition FixedDeque.h:214
const_reverse_iterator rbegin() const
Definition FixedDeque.h:358
~FixedDeque()
Definition FixedDeque.h:262
const_iterator end() const
Definition FixedDeque.h:347
reverse_iterator rend()
Definition FixedDeque.h:363
iterator begin()
Definition FixedDeque.h:332
FixedDeque()
Definition FixedDeque.h:239
FixedDeque & operator=(const FixedDeque &x)
Definition FixedDeque.h:267
reference operator[](size_type idx)
Definition FixedDeque.h:306
void push_front(const T &data)
Definition FixedDeque.h:431
reverse_iterator rbegin()
Definition FixedDeque.h:353
FixedDeque_iterator< T, T &, T *, FixedDeque *, MaxSize > iterator
Definition FixedDeque.h:206
std::ptrdiff_t difference_type
Definition FixedDeque.h:205
iterator end()
Definition FixedDeque.h:342
FixedDeque(size_type n, const T &data=T())
Definition FixedDeque.h:243
const_reference at(size_type idx) const
Definition FixedDeque.h:324
iterator insert(iterator pos, const T &data)
Definition FixedDeque.h:472
iterator erase(iterator first, iterator last)
Definition FixedDeque.h:498
value_type * pointer
Definition FixedDeque.h:210
const_reference front() const
Definition FixedDeque.h:380
void pop_front()
Definition FixedDeque.h:440
reference at(size_type idx)
Definition FixedDeque.h:316
bool full() const
Definition FixedDeque.h:295
reference front()
Definition FixedDeque.h:374
FixedDeque_iterator< T, const T &, const T *, const FixedDeque *, MaxSize > const_iterator
Definition FixedDeque.h:207
bool empty() const
Definition FixedDeque.h:290
friend bool operator==(const FixedDeque< U, N > &x, const FixedDeque< U, N > &y)
reference back()
Definition FixedDeque.h:386
void assign(size_type n, const T &data)
Definition FixedDeque.h:447
FixedDeque(const FixedDeque &x)
Definition FixedDeque.h:256
void resize(size_type n, const T &data=T())
Definition FixedDeque.h:398
size_type size() const
Definition FixedDeque.h:275
void pop_back()
Definition FixedDeque.h:424
T value_type
Definition FixedDeque.h:203
const value_type & const_reference
Definition FixedDeque.h:209
Definition ContainerException.h:23
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