1 #ifndef CONTAINER_S_V_ITERATOR_H_
2 #define CONTAINER_S_V_ITERATOR_H_
26 #include <type_traits>
31 template <
typename T,
size_t N>
32 class SegmentedVector;
58 typename P =
const T*,
59 typename R =
const T&,
60 bool is_const_iterator =
true
63 std::random_access_iterator_tag, T, std::ptrdiff_t, P, R>
89 assert(m_c !=
nullptr && m_p < m_c->size());
92 return *
static_cast<T*
>(
static_cast<void*
>(&(m_c->m_blocks[b][i])));
98 assert(m_c !=
nullptr && m_p < m_c->size());
101 return static_cast<T*
>(
static_cast<void*
>(&(m_c->m_blocks[b][i])));
107 if (m_c !=
nullptr) {
108 if (m_p < m_c->m_size - 1)
127 if (m_c !=
nullptr) {
128 if (m_p > 0 && m_p != m_end)
130 else if (m_p == m_end)
147 return (m_p == other.m_p) && (m_c == other.m_c);
153 return (m_p != other.m_p) || (m_c != other.m_c);
163 assert(m_p + n != m_end);
164 size_t b = (m_p + n) / N;
165 size_t i = (m_p + n) % N;
166 return *
static_cast<T*
>(
static_cast<void*
>(&(m_c->m_blocks[b][i])));
173 if (m_p > m_c->m_size)
199 return m_p - other.m_p;
205 return m_p < other.m_p;
211 return m_p <= other.m_p;
217 return m_p > other.m_p;
223 return m_p >= other.m_p;
234 constexpr
static std::size_t m_end = std::numeric_limits<size_t>::max();
238 using container_pointer_type =
typename std::conditional<
242 container_pointer_type m_c;
246 SVIterator(std::size_t p, container_pointer_type c) : m_p(p), m_c(c) {}
249 bool IsDefaultContructed()
251 return m_c ==
nullptr && m_p == m_end;
257 return m_c !=
nullptr && m_p == m_end;
261 bool IsDereferencable()
263 return m_c !=
nullptr && m_p < m_c->size();
SVIterator(const self_type &other)
Copy constructor.
SVIterator()
Default constructor.
bool operator<(const self_type &other) const
Returns whether iterator is before other.
self_type & operator-=(std::ptrdiff_t n)
Set iterator to n-th previous element.
self_type & operator+=(std::ptrdiff_t n)
Set iterator to n-th next element.
bool operator>=(const self_type &other) const
Returns whether iterator is not after other.
self_type operator+(std::ptrdiff_t n)
Return iterator pointing to n-th next element.
see the online C++11 documentation
Namespace for the core simulator.
self_type & operator++()
Pre-increment (returns position after increment)
bool operator==(const self_type &other) const
Iterator equality.
R operator[](std::size_t n) const
Direct access to n-th element.
self_type operator++(int)
Post-increment (returns position prior to increment)
self_type & operator--()
Pre-decrement (returns position after decrement)
self_type operator--(int)
Pre-increment (returns position after decrement)
long int operator-(const self_type &other) const
Return distance between iterators.
bool operator>(const self_type &other) const
Returns whether iterator is after other.
R operator*() const
Element access.
P operator->() const
Member of element access.
bool operator<=(const self_type &other) const
Returns whether iterator is not after other.
Implementation of iterator for SegmentedVector.
bool operator!=(const self_type &other) const
Iterator inequality.
Container that stores objects "almost contiguously" and guarantees that pointers/iterators are not in...
self_type operator-(std::ptrdiff_t)
Return iterator pointing to n-th previous element.