25 #include <type_traits>
30 template <
typename T,
size_t N>
31 class SegmentedVector;
54 template <
typename T, std::
size_t N,
typename P = const T*,
typename R = const T&,
bool is_const_iterator = true>
55 class SVIterator :
public std::iterator<std::random_access_iterator_tag, T, std::ptrdiff_t, P, R>
81 assert(
m_c !=
nullptr && m_p < m_c->size());
84 return *
static_cast<T*
>(
static_cast<void*
>(&(
m_c->m_blocks[b][i])));
90 assert(
m_c !=
nullptr && m_p < m_c->size());
93 return static_cast<T*
>(
static_cast<void*
>(&(
m_c->m_blocks[b][i])));
100 if (m_p < m_c->m_size - 1)
119 if (
m_c !=
nullptr) {
150 size_t b = (
m_p + n) / N;
151 size_t i = (
m_p + n) % N;
152 return *
static_cast<T*
>(
static_cast<void*
>(&(
m_c->m_blocks[b][i])));
self_type operator-(std::ptrdiff_t)
Return iterator pointing to n-th previous element.
R operator[](std::size_t n) const
Direct access to n-th element.
long int operator-(const self_type &other) const
Return distance between iterators.
bool operator<(const self_type &other) const
Returns whether iterator is before other.
container_pointer_type m_c
self_type operator++(int)
Post-increment (returns position prior to increment)
SVIterator(std::size_t p, container_pointer_type c)
Private constructor, currently only container itself can create iterators.
bool IsDefaultContructed()
See class description.
self_type & operator++()
Pre-increment (returns position after increment)
self_type operator--(int)
Pre-increment (returns position after decrement)
typename std::conditional< is_const_iterator, const SegmentedVector< T, N > *, SegmentedVector< T, N > * >::type container_pointer_type
Type of pointer-to-container (i.e. its const qualification).
bool operator!=(const self_type &other) const
Iterator inequality.
bool operator>(const self_type &other) const
Returns whether iterator is after other.
bool IsDereferencable()
See class description.
bool IsPastTheEnd()
See class description.
T const & max(T const &a, T const &b)
self_type & operator-=(std::ptrdiff_t n)
Set iterator to n-th previous element.
self_type operator+(std::ptrdiff_t n)
Return iterator pointing to n-th next element.
self_type & operator--()
Pre-decrement (returns position after decrement)
bool operator<=(const self_type &other) const
Returns whether iterator is not after other.
Implementation of iterator for SegmentedVector.
P operator->() const
Member of element access.
bool operator>=(const self_type &other) const
Returns whether iterator is not after other.
SVIterator()
Default constructor.
Container that stores objects "almost contiguously" and guarantees that pointers/iterators are not in...
self_type & operator+=(std::ptrdiff_t n)
Set iterator to n-th next element.
bool operator==(const self_type &other) const
Iterator equality.
SVIterator(const self_type &other)
Copy constructor.
R operator*() const
Element access.
SVIterator< T, N, P, R, is_const_iterator > self_type
std::size_t m_p
Current iterator position in the container.
static constexpr std::size_t m_end
One past the last element iterator position.