6#ifndef DUNE_COMMON_TYPETREE_TRAVERSAL_HH
7#define DUNE_COMMON_TYPETREE_TRAVERSAL_HH
23 template<
class Callable,
class Arg0,
class Arg1>
24 constexpr void invokeWithTwoOrOneArg(Callable&& callable, Arg0&& arg0, Arg1&& arg1) {
25 static_assert(std::invocable<Callable&&, Arg0&&, Arg1&&> || std::invocable<Callable&&, Arg0&&>);
26 if constexpr (std::invocable<Callable&&, Arg0&&, Arg1&&>)
28 else if constexpr (std::invocable<Callable&&, Arg0&&>)
44 constexpr void operator()(T&&...)
const { }
66 template<Concept::InnerTreeNode Tree,
class Callable>
70 for (std::size_t i = 0; i != container.degree(); ++i)
71 Impl::invokeWithTwoOrOneArg(at_value, std::forward<Tree>(container).
child(i), i);
74 [&](
auto... i) { (Impl::invokeWithTwoOrOneArg(at_value, std::forward<Tree>(container).
child(i), i), ...); },
75 std::make_index_sequence<std::remove_cvref_t<Tree>::degree()>{});
88 template<Concept::TreeNode Tree,
class TreePath,
class PreFunc,
class LeafFunc,
class PostFunc>
89 void forEachNode(Tree&& tree,
TreePath treePath, PreFunc&& preFunc, LeafFunc&& leafFunc, PostFunc&& postFunc)
91 if constexpr(Concept::LeafTreeNode<std::decay_t<Tree>>) {
92 Impl::invokeWithTwoOrOneArg(leafFunc, tree,
treePath);
94 Impl::invokeWithTwoOrOneArg(preFunc, tree,
treePath);
99 std::forward<Child>(
child),
106 Impl::invokeWithTwoOrOneArg(postFunc, tree,
treePath);
132 template<
class Tree,
class PreNodeFunc,
class LeafNodeFunc,
class PostNodeFunc>
133 void forEachNode(Tree&& tree, PreNodeFunc&& preNodeFunc, LeafNodeFunc&& leafNodeFunc, PostNodeFunc&& postNodeFunc)
135 Impl::forEachNode(tree,
treePath(), preNodeFunc, leafNodeFunc, postNodeFunc);
147 template<Concept::TreeNode Tree,
class NodeFunc>
162 template<Concept::TreeNode Tree,
class LeafFunc>
decltype(auto) constexpr unpackIntegerSequence(F &&f, std::integer_sequence< I, i... > sequence)
Unpack an std::integer_sequence<I,i...> to std::integral_constant<I,i>...
Definition indices.hh:124
decltype(auto) child(Node &&node, TreePath< Indices... > treePath)
Extracts the child of a node given by a TreePath object.
Definition childaccess.hh:55
typename Impl::ChildTraits< Node, indices... >::type Child
Template alias for the type of a child node given by a list of child indices.
Definition childaccess.hh:129
void forEachNode(Tree &&tree, PreNodeFunc &&preNodeFunc, LeafNodeFunc &&leafNodeFunc, PostNodeFunc &&postNodeFunc)
Traverse tree and visit each node.
Definition traversal.hh:133
constexpr void forEachChild(Tree &&container, Callable &&at_value)
Traverse each child of a tree and apply a callable function.
Definition traversal.hh:67
void forEachLeafNode(Tree &&tree, LeafFunc &&leafFunc)
Traverse tree and visit each leaf node.
Definition traversal.hh:163
Dune::HybridMultiIndex< T... > TreePath
A type for representing tree paths that supports both compile time and run time indices.
Definition treepath.hh:43
constexpr auto treePath(const T &... t)
Constructs a new TreePath from the given indices.
Definition treepath.hh:55
Definition childaccess.hh:23
constexpr HybridMultiIndex< T..., std::size_t > push_back(const HybridMultiIndex< T... > &tp, std::size_t i)
Appends a run time index to a HybridMultiIndex.
Definition hybridmultiindex.hh:249
Model of an inner node of a typetree with uniform nodes accessible via runtime index.
Definition nodeconcepts.hh:52