26 #include <type_traits> 31 template <
typename T, std::
size_t N,
bool Safe>
32 class SegmentedVector;
55 template <
typename T, std::size_t N,
bool Safe,
typename P =
const T*,
typename R =
const T&,
56 bool is_const_iterator =
true>
92 assert(
m_c !=
nullptr && 0 <=
m_p && m_p < m_c->m_size);
93 return *
static_cast<T*
>(
static_cast<void*
>(&(
m_c->m_blocks[
m_p / N][
m_p % N])));
99 assert(
m_c !=
nullptr && 0 <=
m_p && m_p < m_c->m_size);
100 return static_cast<T*
>(
static_cast<void*
>(&(
m_c->m_blocks[
m_p / N][
m_p % N])));
106 assert(
m_c !=
nullptr && 0 <=
m_p && m_p <= m_c->m_size);
109 assert(
m_c !=
nullptr && 0 <=
m_p && m_p <= m_c->m_size);
124 assert(
m_c !=
nullptr && 0 <=
m_p && m_p <= m_c->m_size);
127 assert(
m_c !=
nullptr && 0 <=
m_p && m_p <= m_c->m_size);
152 assert(
m_c !=
nullptr && 0 <=
m_p + n &&
m_p + n < m_c->m_size);
153 return *
static_cast<T*
>(
static_cast<void*
>(&(
m_c->m_blocks[(
m_p + n) / N][(
m_p + n) % N])));
159 assert(
m_c !=
nullptr && 0 <=
m_p && m_p <= m_c->m_size);
168 assert(
m_c !=
nullptr && 0 <=
m_p && m_p <= m_c->m_size);
171 assert(
m_c !=
nullptr && 0 <=
m_p && m_p <= m_c->m_size);
178 assert(
m_c !=
nullptr && 0 <=
m_p && m_p <= m_c->m_size);
179 assert(
m_c !=
nullptr && 0 <=
m_p + n &&
m_p + n <= m_c->m_size);
186 assert(
m_c !=
nullptr && 0 <=
m_p && m_p <= m_c->m_size);
187 assert(
m_c !=
nullptr && 0 <=
m_p - n &&
m_p - n <= m_c->m_size);
194 assert(
m_c !=
nullptr && 0 <=
m_p && m_p <= m_c->m_size);
195 assert(other.
m_c !=
nullptr && 0 <= other.
m_p && other.
m_p <= other.
m_c->m_size);
202 assert(
m_c !=
nullptr && 0 <=
m_p && m_p <= m_c->m_size);
203 assert(other.
m_c !=
nullptr && 0 <= other.
m_p && other.
m_p <= other.
m_c->m_size);
210 assert(
m_c !=
nullptr && 0 <=
m_p && m_p <= m_c->m_size);
211 assert(other.
m_c !=
nullptr && 0 <= other.
m_p && other.
m_p <= other.
m_c->m_size);
218 assert(
m_c !=
nullptr && 0 <=
m_p && m_p <= m_c->m_size);
219 assert(other.
m_c !=
nullptr && 0 <= other.
m_p && other.
m_p <= other.
m_c->m_size);
226 assert(
m_c !=
nullptr && 0 <=
m_p && m_p <= m_c->m_size);
227 assert(other.
m_c !=
nullptr && 0 <= other.
m_p && other.
m_p <= other.
m_c->m_size);
236 using container_pointer_type =
typename std::conditional<is_const_iterator, const SegmentedVector<T, N, Safe>*,
251 template <
typename T, std::size_t N,
bool Safe,
typename P =
const T*,
typename R =
const T&,
252 bool is_const_iterator =
true>
256 return p.operator+(i);
259 template <
typename T, std::size_t N,
bool Safe,
typename P =
const T*,
typename R =
const T&,
260 bool is_const_iterator =
true>
264 return p.operator-(i);
bool operator<=(const self_type &other) const
Returns whether iterator is not after other.
SVIterator(const self_type &other)
Copy constructor.
self_type & operator+=(std::ptrdiff_t n)
Set iterator to n-th next element.
std::random_access_iterator_tag iterator_category
self_type operator-(std::ptrdiff_t n)
Return iterator pointing to n-th previous element.
SVIterator(std::size_t p, container_pointer_type c)
Private constructor, currently only container itself can create iterators.
bool operator>=(const self_type &other) const
Returns whether iterator is not after other.
bool operator<(const self_type &other) const
Returns whether iterator is before other.
R operator[](std::size_t n) const
Direct access to n-th element.
self_type & operator-=(std::ptrdiff_t n)
Set iterator to n-th previous element.
typename std::conditional< is_const_iterator, const SegmentedVector< T, N, Safe > *, SegmentedVector< T, N, Safe > * >::type container_pointer_type
Type of pointer-to-container (i.e. its const qualification).
P operator->() const
Member of element access.
long int operator-(const self_type &other) const
Return distance between iterators.
const self_type operator++(int)
Post-increment (returns position prior to increment)
std::size_t m_p
Current iterator position in the container.
SVIterator< T, N, Safe, P, R, is_const_iterator > self_type
Container that stores objects "almost contiguously" (in a chain of blocks) and guarantees that pointe...
bool operator==(const self_type &other) const
Iterator equality.
self_type operator+(std::ptrdiff_t n)
Return iterator pointing to n-th next element.
std::ptrdiff_t difference_type
self_type & operator--()
Pre-decrement (returns position after decrement)
const self_type operator--(int)
Pre-increment (returns position after decrement)
self_type & operator++()
Pre-increment (returns position after increment)
bool operator!=(const self_type &other) const
Iterator inequality.
Implementation of iterator for SegmentedVector.
bool operator>(const self_type &other) const
Returns whether iterator is after other.
container_pointer_type m_c
Container that the iterator points into.
Namespace for the simulator and related classes.
R operator*() const
Element access.
SVIterator()
Default constructor.