11namespace hi::inline
v1 {
19template<
typename Key,
typename T,
typename Compare = std::less<Key>>
25 constexpr ~tree() =
default;
26 constexpr tree(
tree const&)
noexcept =
default;
27 constexpr tree(
tree&&)
noexcept =
default;
28 constexpr tree& operator=(
tree const&)
noexcept =
default;
29 constexpr tree& operator=(
tree&&)
noexcept =
default;
30 constexpr tree()
noexcept =
default;
39 value_type&
operator()(
auto path_first,
auto path_last)
noexcept
41 auto *ptr = find_or_create(path_first, path_last);
42 hi_axiom(ptr !=
nullptr);
54 value_type
const&
operator()(
auto path_first,
auto path_last)
const noexcept
56 auto *ptr = find(path_first, path_last, [](value_type
const&) ->
void {});
57 hi_axiom(ptr !=
nullptr);
70 return this->operator()(cbegin(key), cend(key));
79 value_type
const&
operator[](
auto const& path)
const noexcept
83 return this->operator()(cbegin(path), cend(path));
92 void walk(
auto path_first,
auto path_last,
auto&& func)
noexcept
94 if (
auto element = find(path_first, path_last, [](value_type&) ->
void {})) {
105 void walk(
auto path_first,
auto path_last,
auto&& func)
const noexcept
107 if (
auto element =
find(path_first, path_last, [](value_type
const&) ->
void {})) {
117 void walk(
auto const& key,
auto&& func)
noexcept
121 return walk(cbegin(key), cend(key),
hi_forward(func));
129 void walk(
auto const& key,
auto&& func)
const noexcept
133 return walk(cbegin(key), cend(key),
hi_forward(func));
145 if (
auto element = find(path_first, path_last, func)) {
146 _walk(element, func);
159 if (
auto element = find(path_first, path_last, func)) {
160 _walk(element, func);
174 return walk_including_path(cbegin(path), cend(path),
hi_forward(func));
187 return walk_including_path(cbegin(path), cend(path),
hi_forward(func));
194 void walk(
auto&& func)
noexcept
203 void walk(
auto&& func)
const noexcept
223 [[nodiscard]]
constexpr node_type *find(
auto path_first,
auto path_last,
auto const& func)
noexcept
226 for (
auto path_it = path_first; path_it != path_last; ++path_it) {
229 if (
auto node_it = node->children.find(*path_it); node_it != node->children.end()) {
230 node = &node_it->second;
245 [[nodiscard]]
constexpr node_type
const *
find(
auto path_first,
auto path_last,
auto const& func)
const noexcept
248 for (
auto path_it = path_first; path_it != path_last; ++path_it) {
251 if (
auto node_it = node->children.find(*path_it); node_it != node->children.end()) {
260 [[nodiscard]]
constexpr node_type *find_or_create(
auto path_first,
auto path_last)
noexcept
263 for (
auto path_it = path_first; path_it != path_last; ++path_it) {
264 node = &node->children[*path_it];
274 constexpr void _walk(node_type *node,
auto const& func)
noexcept
277 for (
auto& child : node->children) {
278 _walk(&child.second, func);
287 constexpr void _walk(node_type
const *node,
auto const& func)
const noexcept
290 for (
auto& child : node->children) {
291 _walk(&child.second, func);
Utilities used by the HikoGUI library itself.
#define hi_forward(x)
Forward a value, based on the decltype of the value.
Definition utility.hpp:29
DOXYGEN BUG.
Definition algorithm.hpp:15
A tree container.
Definition tree.hpp:20
void walk(auto &&func) const noexcept
Walk the full tree.
Definition tree.hpp:203
value_type const & operator()(auto path_first, auto path_last) const noexcept
Find the node and return the value of the node.
Definition tree.hpp:54
void walk_including_path(auto const &path, auto &&func) const noexcept
Walk the tree starting at path, and also for each node along the path.
Definition tree.hpp:183
value_type & operator[](auto const &key) noexcept
Find or create the node and return the value of the node.
Definition tree.hpp:66
void walk_including_path(auto path_first, auto path_last, auto const &func) const noexcept
Walk the tree starting at path, and also for each node along the path.
Definition tree.hpp:157
value_type const & operator[](auto const &path) const noexcept
Find the node and return the value of the node.
Definition tree.hpp:79
void walk_including_path(auto const &path, auto &&func) noexcept
Walk the tree starting at path, and also for each node along the path.
Definition tree.hpp:170
void walk_including_path(auto path_first, auto path_last, auto const &func) noexcept
Walk the tree starting at path, and also for each node along the path.
Definition tree.hpp:143
value_type & operator()(auto path_first, auto path_last) noexcept
Find or create the node and return the value of the node.
Definition tree.hpp:39
void walk(auto &&func) noexcept
Walk the full tree.
Definition tree.hpp:194