7#include "../utility/utility.hpp"
8#include "../macros.hpp"
13hi_export_module(hikogui.algorithm.recursive_iterator);
15hi_export
namespace hi {
22template<
typename ParentIt>
25 using child_iterator = std::conditional_t<
26 std::is_const_v<std::remove_reference_t<typename std::iterator_traits<ParentIt>::reference>>,
91 return _parent_it == _parent_it_end;
101 return &(*_child_it);
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;
171 constexpr recursive_iterator& operator-=(difference_type rhs)
noexcept
174 return (*
this) += -rhs;
182 _child_it =
std::end(*_parent_it) - 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) {
251 parent_iterator _parent_it;
252 parent_iterator _parent_it_end;
253 child_iterator _child_it;
258template<
typename Container>
266template<
typename Container>
274template<
typename Container>
282template<
typename Container>
@ end
Start from the end of the file.
@ begin
Start from the beginning of the file.
@ other
The gui_event does not have associated data.
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
The HikoGUI namespace.
Definition recursive_iterator.hpp:15
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 Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:378
An iterator which recursively iterates through nested containers.
Definition recursive_iterator.hpp:23
constexpr child_iterator child() const noexcept
Get the current child iterator.
Definition recursive_iterator.hpp:76
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 bool at_end() const noexcept
Check if the iterator is at end.
Definition recursive_iterator.hpp:89
constexpr recursive_iterator(parent_iterator parent_it_end) noexcept
Create an end iterator one beyond the last child.
Definition recursive_iterator.hpp:61
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
constexpr parent_iterator parent() const noexcept
Get the current parent iterator.
Definition recursive_iterator.hpp:68