28 template<
class container_t>
33 template<
class container_t_,
class derived_t_>
36 template<
class container_t_,
class derived_t_>
39 using difference_type =
typename container_t::difference_type;
40 using size_type =
typename container_t::size_type;
41 using value_type =
typename container_t::value_type;
42 using pointer =
typename container_t::pointer;
43 using const_pointer =
typename container_t::const_pointer;
44 using reference =
typename container_t::reference;
45 using const_reference =
typename container_t::const_reference;
47 using iterator_category = std::contiguous_iterator_tag;
48 using iterator_concept = std::contiguous_iterator_tag;
52 constexpr
base_iterator(container_t* pContainer, size_type nIndex) noexcept
54 , m_pContainer(pContainer)
57 constexpr
operator void*() noexcept
59 return &(*m_pContainer).at(m_nIndex);
63 void shift(difference_type nShift) noexcept
67 auto&& get(difference_type nShift = 0)
const noexcept
69 return (*m_pContainer).at(m_nIndex + nShift);
71 size_type get_index()
const noexcept
77 size_type m_nIndex = 0u;
78 container_t* m_pContainer =
nullptr;
91 template<
class container_t,
class derived_t>
95 using decayed_derived_type = std::decay_t<derived_t>;
98 using super_type::super_type;
100 template<
class iterator_t>
101 requires derived_from_template_c<iterator_t, base_iterator>
102 constexpr
typename super_type::difference_type operator-(
const iterator_t& r)
const noexcept
104 return static_cast<typename super_type::difference_type
>(super_type::get_index() - r.get_index());
108 return super_type::get_index() < r.get_index();
112 return super_type::get_index() <= r.get_index();
116 return super_type::get_index() > r.get_index();
120 return super_type::get_index() >= r.get_index();
124 return super_type::get_index() != r.get_index();
128 return super_type::get_index() == r.get_index();
130 constexpr decayed_derived_type& operator++() noexcept
132 super_type::shift(1);
133 return static_cast<decayed_derived_type&
>(*this);
135 constexpr decayed_derived_type& operator--() noexcept
137 super_type::shift(-1);
138 return static_cast<decayed_derived_type&
>(*this);
140 [[nodiscard]] constexpr decayed_derived_type operator++(
int) noexcept
142 decayed_derived_type r(
static_cast<const decayed_derived_type&
>(*
this));
143 super_type::shift(1);
146 [[nodiscard]] constexpr decayed_derived_type operator--(
int) noexcept
148 decayed_derived_type r(
static_cast<const decayed_derived_type&
>(*
this));
149 super_type::shift(-1);
152 constexpr decayed_derived_type& operator+=(
typename super_type::difference_type n) noexcept
154 super_type::shift(n);
155 return static_cast<decayed_derived_type&
>(*this);
157 constexpr decayed_derived_type& operator-=(
typename super_type::difference_type n) noexcept
159 super_type::shift(-n);
160 return static_cast<decayed_derived_type&
>(*this);
162 constexpr decayed_derived_type operator+(
typename super_type::difference_type n)
const noexcept
164 decayed_derived_type r(
static_cast<const decayed_derived_type&
>(*
this));
167 constexpr decayed_derived_type operator-(
typename super_type::difference_type n)
const noexcept
169 decayed_derived_type r(
static_cast<const decayed_derived_type&
>(*
this));
174 template<
class iterator_t>
175 requires derived_from_template_c<iterator_t, base_forward_iterator>
176 constexpr iterator_t operator+(
typename iterator_t::size_type n, iterator_t it) noexcept
191 template<
class container_t,
class derived_t>
195 using decayed_derived_type = std::decay_t<derived_t>;
198 using super_type::super_type;
200 template<
class iterator_t>
201 requires derived_from_template_c<iterator_t, base_iterator>
202 constexpr
typename super_type::difference_type operator-(
const iterator_t& r)
const noexcept
204 return static_cast<typename super_type::difference_type
>(r.get_index() - super_type::get_index());
210 return super_type::get_index() + 1 > r.get_index() + 1;
214 return super_type::get_index() + 1 >= r.get_index() + 1;
218 return super_type::get_index() + 1 < r.get_index() + 1;
222 return super_type::get_index() + 1 <= r.get_index() + 1;
226 return super_type::get_index() + 1 != r.get_index() + 1;
230 return super_type::get_index() + 1 == r.get_index() + 1;
232 constexpr decayed_derived_type& operator++() noexcept
234 super_type::shift(-1);
235 return static_cast<decayed_derived_type&
>(*this);
237 constexpr decayed_derived_type& operator--() noexcept
239 super_type::shift(1);
240 return static_cast<decayed_derived_type&
>(*this);
242 [[nodiscard]] constexpr decayed_derived_type operator++(
int) noexcept
244 decayed_derived_type r(
static_cast<const decayed_derived_type&
>(*
this));
245 super_type::shift(-1);
248 [[nodiscard]] constexpr decayed_derived_type operator--(
int) noexcept
250 decayed_derived_type r(
static_cast<const decayed_derived_type&
>(*
this));
251 super_type::shift(1);
254 constexpr decayed_derived_type& operator+=(
typename super_type::difference_type n) noexcept
256 super_type::shift(-n);
257 return static_cast<decayed_derived_type&
>(*this);
259 constexpr decayed_derived_type& operator-=(
typename super_type::difference_type n) noexcept
261 super_type::shift(n);
262 return static_cast<decayed_derived_type&
>(*this);
264 constexpr decayed_derived_type operator+(
typename super_type::difference_type n)
const noexcept
266 decayed_derived_type r(
static_cast<const decayed_derived_type&
>(*
this));
269 constexpr decayed_derived_type operator-(
typename super_type::difference_type n)
const noexcept
271 decayed_derived_type r(
static_cast<const decayed_derived_type&
>(*
this));
276 template<
class iterator_t>
277 requires derived_from_template_c<iterator_t, base_reverse_iterator>
278 constexpr iterator_t operator+(
typename iterator_t::size_type n, iterator_t it) noexcept
Basic contiguous forward iterator, meaning that incrementing an iterator will lead it moving forward.
Base contiguous iterator with a container pointer and an index.
Basic contiguous reverse iterator, meaning that incrementing an iterator will lead it moving backward...