qxLib
iterator.h
Go to the documentation of this file.
1 /**
2 
3  @file iterator.h
4  @author Khrapov
5  @date 2.12.2023
6  @copyright (c) Nick Khrapov, 2023. All right reserved.
7 
8 **/
9 #pragma once
10 
12 
13 namespace qx
14 {
15 
16 template<class container_t, class derived_t = void>
17 class const_iterator;
18 
19 /**
20 
21  @class iterator
22  @brief Non-const random access iterator type
23  @details Use it for range-based loops and std algorithms
24  container_t have to provide at(size_t)
25  @tparam container_t - container type
26  @author Khrapov
27  @date 27.07.2019
28 
29 **/
30 template<class container_t, class derived_t = void>
31 class iterator
32  : public base_forward_iterator<
33  container_t,
34  std::conditional_t<std::same_as<derived_t, void>, iterator<container_t>, derived_t>>
35 {
36  friend class const_iterator<container_t, derived_t>;
37 
38  using super_type =
40 
41 public:
43 
44  [[nodiscard]] constexpr typename super_type::reference operator*() const noexcept;
45  [[nodiscard]] constexpr typename super_type::pointer operator->() const noexcept;
46  [[nodiscard]] constexpr typename super_type::reference operator[](typename super_type::size_type i) const noexcept;
47 };
48 
49 /**
50 
51  @class const_iterator
52  @brief Const random access iterator type
53  @details Use it for range-based loops and std algorithms
54  container_t have to provide at(size_t)
55  @tparam container_t - container type
56  @author Khrapov
57  @date 27.07.2019
58 
59 **/
60 template<class container_t, class derived_t>
62  : public base_forward_iterator<
63  const container_t,
64  std::conditional_t<std::same_as<derived_t, void>, const const_iterator<container_t>, derived_t>>
65 {
67  const container_t,
68  std::conditional_t<std::same_as<derived_t, void>, const const_iterator, derived_t>>;
69 
70 public:
72 
73  constexpr const_iterator(const iterator<container_t>& it) noexcept;
74  [[nodiscard]] constexpr typename super_type::const_reference operator*() const noexcept;
75  [[nodiscard]] constexpr typename super_type::const_pointer operator->() const noexcept;
76  [[nodiscard]] constexpr typename super_type::const_reference operator[](
77  typename super_type::size_type m) const noexcept;
78 };
79 
80 template<class container_t, class derived_t = void>
82 
83 /**
84 
85  @class reverse_iterator
86  @brief Non-const random access reverse iterator type
87  @details Use it for range-based loops and std algorithms
88  container_t have to provide at(size_t)
89  @tparam container_t - container type
90  @author Khrapov
91  @date 27.07.2019
92 
93 **/
94 template<class container_t, class derived_t = void>
96  : public base_reverse_iterator<
97  container_t,
98  std::conditional_t<std::same_as<derived_t, void>, reverse_iterator<container_t>, derived_t>>
99 {
100  friend class const_reverse_iterator<container_t>;
101 
103  container_t,
104  std::conditional_t<std::same_as<derived_t, void>, reverse_iterator, derived_t>>;
105 
106 public:
108 
109  [[nodiscard]] constexpr typename super_type::reference operator*() const noexcept;
110  [[nodiscard]] constexpr typename super_type::pointer operator->() const noexcept;
111  [[nodiscard]] constexpr typename super_type::reference operator[](typename super_type::size_type m) const noexcept;
112 };
113 
114 /**
115 
116  @class const_reverse_iterator
117  @brief Const reverse random access iterator type
118  @details Use it for range-based loops and std algorithms
119  container_t have to provide at(size_t)
120  @tparam container_t - container type
121  @author Khrapov
122  @date 19.03.2020
123 
124 **/
125 template<class container_t, class derived_t>
127  : public base_reverse_iterator<
128  const container_t,
129  std::conditional_t<std::same_as<derived_t, void>, const const_reverse_iterator<container_t>, derived_t>>
130 {
132  const container_t,
133  std::conditional_t<std::same_as<derived_t, void>, const const_reverse_iterator, derived_t>>;
134 
135 public:
137 
138  constexpr const_reverse_iterator(const reverse_iterator<container_t>& it) noexcept;
139  [[nodiscard]] constexpr typename super_type::const_reference operator*() const noexcept;
140  [[nodiscard]] constexpr typename super_type::const_pointer operator->() const noexcept;
141  [[nodiscard]] constexpr typename super_type::const_reference operator[](
142  typename super_type::size_type m) const noexcept;
143 };
144 
145 } // namespace qx
146 
Basic contiguous forward iterator, meaning that incrementing an iterator will lead it moving forward.
Definition: base_iterator.h:81
Base contiguous iterator with a container pointer and an index.
Definition: base_iterator.h:31
Basic contiguous reverse iterator, meaning that incrementing an iterator will lead it moving backward...
Const random access iterator type.
Definition: iterator.h:65
Const reverse random access iterator type.
Definition: iterator.h:130
Non-const random access iterator type.
Definition: iterator.h:35
Non-const random access reverse iterator type.
Definition: iterator.h:99