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>
69 if constexpr (Concept::UniformInnerTreeNode<Tree>)
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)
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)
147 template<Concept::TreeNode Tree,
class NodeFunc>
162 template<Concept::TreeNode Tree,
class LeafFunc>
172 #endif // DUNE_COMMON_TYPETREE_TRAVERSAL_HH 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
decltype(auto) constexpr unpackIntegerSequence(F &&f, [[maybe_unused]] std::integer_sequence< I, i... > sequence)
Unpack an std::integer_sequence<I,i...> to std::integral_constant<I,i>...
Definition: indices.hh:124
constexpr void forEachChild(Tree &&container, Callable &&at_value)
Traverse each child of a tree and apply a callable function.
Definition: traversal.hh:67
void forEachNode(Tree &&tree, NodeFunc &&nodeFunc)
Traverse tree and visit each node.
Definition: traversal.hh:148
I i
Definition: hybridmultiindex.hh:328
Definition: childaccess.hh:23
decltype(auto) child(Node &&node, TreePath< Indices... > treePath)
Extracts the child of a node given by a TreePath object.
Definition: childaccess.hh:55
Dune::HybridMultiIndex< T... > TreePath
A type for representing tree paths that supports both compile time and run time indices.
Definition: treepath.hh:43
void forEachNode(Tree &&tree, PreNodeFunc &&preNodeFunc, LeafNodeFunc &&leafNodeFunc, PostNodeFunc &&postNodeFunc)
Traverse tree and visit each node.
Definition: traversal.hh:133
concept LeafTreeNode
Model of a leaf tree node of a typetree.
Definition: nodeconcepts.hh:63
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
void forEachLeafNode(Tree &&tree, LeafFunc &&leafFunc)
Traverse tree and visit each leaf node.
Definition: traversal.hh:163