3 #include <dune/common/version.hh> 4 #include <dune/common/rangeutilities.hh> 5 #include <dune/common/std/type_traits.hh> 7 #include <dune/typetree/nodetags.hh> 8 #include <dune/typetree/treepath.hh> 10 #include <amdis/common/ForEach.hpp> 11 #include <amdis/common/TypeTraits.hpp> 19 using HasDynamicChildAccess = decltype(std::declval<Tree>().child(0u));
26 template <
class Tree,
class TreePath,
class Pre,
class Leaf,
class Post>
27 void forEachNode(
Tree&& tree, TreePath treePath, Pre&& preFunc, Leaf&& leafFunc, Post&& postFunc)
29 using TreeType = std::decay_t<Tree>;
30 if constexpr (TreeType::isLeaf) {
32 leafFunc(tree, treePath);
34 preFunc(tree, treePath);
35 if constexpr(Dune::Std::is_detected_v<HasDynamicChildAccess,TreeType>) {
37 for (std::size_t i = 0; i < tree.degree(); ++i) {
38 auto childTreePath = Dune::TypeTree::push_back(treePath, i);
39 forEachNode(tree.child(i), childTreePath, preFunc, leafFunc, postFunc);
43 const auto indices = std::make_index_sequence<std::size_t(TreeType::degree())>{};
44 Ranges::forIndices(indices, [&](
auto i) {
45 auto childTreePath = Dune::TypeTree::push_back(treePath, i);
46 forEachNode(tree.child(i), childTreePath, preFunc, leafFunc, postFunc);
49 postFunc(tree, treePath);
64 template <
class Tree,
class Pre,
class Leaf,
class Post>
65 void forEachNode(
Tree&& tree, Pre&& preFunc, Leaf&& leafFunc, Post&& postFunc)
67 auto root = Dune::TypeTree::hybridTreePath();
68 forEachNode(tree, root, preFunc, leafFunc, postFunc);
80 template <
class Tree,
class Inner,
class Leaf>
81 void forEachNode(
Tree&& tree, Inner&& innerFunc, Leaf&& leafFunc)
83 auto root = Dune::TypeTree::hybridTreePath();
84 forEachNode(tree, root, innerFunc, leafFunc, NoOp{});
95 template <
class Tree,
class NodeFunc>
96 void forEachNode(
Tree&& tree, NodeFunc&& nodeFunc)
98 auto root = Dune::TypeTree::hybridTreePath();
99 forEachNode(tree, root, nodeFunc, nodeFunc, NoOp{});
110 template <
class Tree,
class Leaf>
111 void forEachLeafNode(
Tree&& tree, Leaf&& leafFunc)
113 auto root = Dune::TypeTree::hybridTreePath();
114 forEachNode(tree, root, NoOp{}, leafFunc, NoOp{});
Definition: AdaptBase.hpp:6