24 using parent_iterator = ParentIt;
25 using child_iterator = std::conditional_t<
26 std::is_const_v<std::remove_reference_t<typename std::iterator_traits<ParentIt>::reference>>,
45 constexpr recursive_iterator(parent_iterator parent_it, parent_iterator parent_it_end, child_iterator child_it) noexcept :
46 _parent_it(parent_it), _parent_it_end(parent_it_end), _child_it(child_it)
52 constexpr recursive_iterator(parent_iterator parent_it, parent_iterator parent_it_end) noexcept :
53 _parent_it(parent_it),
54 _parent_it_end(parent_it_end),
55 _child_it(parent_it != parent_it_end ?
std::begin(*parent_it) : child_iterator{})
62 _parent_it(parent_it_end), _parent_it_end(parent_it_end), _child_it()
68 [[nodiscard]]
constexpr parent_iterator
parent() const noexcept
76 [[nodiscard]]
constexpr child_iterator
child() const noexcept
89 [[nodiscard]]
constexpr bool at_end() const noexcept
91 return _parent_it == _parent_it_end;
94 [[nodiscard]]
constexpr reference operator*() const noexcept
99 [[nodiscard]]
constexpr pointer operator->() const noexcept
101 return &(*_child_it);
104 [[nodiscard]]
constexpr reference operator[](
std::size_t i)
const noexcept
109 constexpr recursive_iterator& operator++() noexcept
112 if (_child_it ==
std::end(*_parent_it)) {
115 _child_it = _parent_it->begin();
121 constexpr recursive_iterator& operator--() noexcept
131 constexpr recursive_iterator operator++(
int)
noexcept
138 constexpr recursive_iterator operator--(
int)
noexcept
145 constexpr recursive_iterator& operator+=(difference_type rhs)
noexcept
148 return (*
this) -= -rhs;
154 if (left_in_child <= rhs) {
159 rhs -= left_in_child;
171 constexpr recursive_iterator& operator-=(difference_type rhs)
noexcept
174 return (*
this) += -rhs;
180 if (left_in_child < rhs) {
182 _child_it =
std::end(*_parent_it) - 1;
183 rhs -= (left_in_child + 1);
195 [[nodiscard]]
constexpr friend bool operator==(recursive_iterator
const& lhs, recursive_iterator
const& rhs)
noexcept
197 if (lhs._parent_it != rhs._parent_it) {
199 }
else if (lhs.at_end()) {
200 hi_axiom(rhs.at_end());
203 return lhs._child_it == rhs._child_it;
207 [[nodiscard]]
constexpr friend std::strong_ordering
208 operator<=>(recursive_iterator
const& lhs, recursive_iterator
const& rhs)
noexcept
210 if (lhs._parent_it != rhs._parent_it) {
211 return (lhs._parent_it - rhs._parent_it) <=> 0;
212 }
else if (lhs.at_end()) {
213 hi_axiom(rhs.at_end());
214 return std::strong_ordering::equal;
216 return (lhs._child_it - rhs._child_it) <=> 0;
220 [[nodiscard]]
constexpr friend recursive_iterator operator+(recursive_iterator lhs, difference_type rhs)
noexcept
224 [[nodiscard]]
constexpr friend recursive_iterator operator-(recursive_iterator lhs, difference_type rhs)
noexcept
228 [[nodiscard]]
constexpr friend recursive_iterator operator+(difference_type lhs, recursive_iterator rhs)
noexcept
233 [[nodiscard]]
constexpr friend difference_type
234 operator-(recursive_iterator
const& lhs, recursive_iterator
const& rhs)
noexcept
240 difference_type
count = 0;
241 while (lhs_._parent_it < rhs._parent_it) {
244 lhs_._child_it =
begin(*lhs_._parent_it);
251 parent_iterator _parent_it;
252 parent_iterator _parent_it_end;
253 child_iterator _child_it;
constexpr auto recursive_iterator_begin(Container &rhs) noexcept
Get a recursive iterator from the begin of a recursive container.
Definition recursive_iterator.hpp:259
constexpr auto recursive_iterator_end(Container &rhs) noexcept
Get a recursive iterator from one beyond the end of a recursive container.
Definition recursive_iterator.hpp:267
constexpr recursive_iterator(parent_iterator parent_it, parent_iterator parent_it_end, child_iterator child_it) noexcept
Create an iterator at an element inside a child container.
Definition recursive_iterator.hpp:45
constexpr recursive_iterator(parent_iterator parent_it, parent_iterator parent_it_end) noexcept
Create a begin iterator at the first child's first element.
Definition recursive_iterator.hpp:52