7#include "../utility/utility.hpp"
8#include "../macros.hpp"
21template<
typename Key,
typename T,
typename Compare = std::less<Key>>
27 constexpr ~tree() =
default;
28 constexpr tree(
tree const&)
noexcept =
default;
29 constexpr tree(
tree&&)
noexcept =
default;
30 constexpr tree& operator=(
tree const&)
noexcept =
default;
31 constexpr tree& operator=(
tree&&)
noexcept =
default;
32 constexpr tree()
noexcept =
default;
41 value_type&
operator()(
auto path_first,
auto path_last)
noexcept
43 auto *ptr = find_or_create(path_first, path_last);
44 hi_assert_not_null(ptr);
56 value_type
const&
operator()(
auto path_first,
auto path_last)
const noexcept
58 auto *ptr = find(path_first, path_last, [](value_type
const&) ->
void {});
59 hi_assert_not_null(ptr);
72 return this->operator()(cbegin(key), cend(key));
81 value_type
const&
operator[](
auto const& path)
const noexcept
85 return this->operator()(cbegin(path), cend(path));
94 void walk(
auto path_first,
auto path_last,
auto&& func)
noexcept
96 if (
auto element = find(path_first, path_last, [](value_type&) ->
void {})) {
97 _walk(element, hi_forward(func));
107 void walk(
auto path_first,
auto path_last,
auto&& func)
const noexcept
109 if (
auto element =
find(path_first, path_last, [](value_type
const&) ->
void {})) {
110 _walk(element, hi_forward(func));
119 void walk(
auto const& key,
auto&& func)
noexcept
123 return walk(cbegin(key), cend(key), hi_forward(func));
131 void walk(
auto const& key,
auto&& func)
const noexcept
135 return walk(cbegin(key), cend(key), hi_forward(func));
147 if (
auto element = find(path_first, path_last, func)) {
148 _walk(element, func);
161 if (
auto element = find(path_first, path_last, func)) {
162 _walk(element, func);
176 return walk_including_path(cbegin(path), cend(path), hi_forward(func));
189 return walk_including_path(cbegin(path), cend(path), hi_forward(func));
196 void walk(
auto&& func)
noexcept
205 void walk(
auto&& func)
const noexcept
225 [[nodiscard]]
constexpr node_type *find(
auto path_first,
auto path_last,
auto const& func)
noexcept
228 for (
auto path_it = path_first; path_it != path_last; ++path_it) {
231 if (
auto node_it = node->children.find(*path_it); node_it != node->children.end()) {
232 node = &node_it->second;
247 [[nodiscard]]
constexpr node_type
const *
find(
auto path_first,
auto path_last,
auto const& func)
const noexcept
250 for (
auto path_it = path_first; path_it != path_last; ++path_it) {
253 if (
auto node_it = node->children.find(*path_it); node_it != node->children.end()) {
262 [[nodiscard]]
constexpr node_type *find_or_create(
auto path_first,
auto path_last)
noexcept
265 for (
auto path_it = path_first; path_it != path_last; ++path_it) {
266 node = &node->children[*path_it];
276 constexpr void _walk(node_type *node,
auto const& func)
noexcept
279 for (
auto& child : node->children) {
280 _walk(&child.second, func);
289 constexpr void _walk(node_type
const *node,
auto const& func)
const noexcept
292 for (
auto& child : node->children) {
293 _walk(&child.second, func);
DOXYGEN BUG.
Definition algorithm.hpp:16
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:377
A tree container.
Definition tree.hpp:22
void walk(auto &&func) const noexcept
Walk the full tree.
Definition tree.hpp:205
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:56
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:185
value_type & operator[](auto const &key) noexcept
Find or create the node and return the value of the node.
Definition tree.hpp:68
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:159
value_type const & operator[](auto const &path) const noexcept
Find the node and return the value of the node.
Definition tree.hpp:81
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:172
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:145
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:41
void walk(auto &&func) noexcept
Walk the full tree.
Definition tree.hpp:196