4 #ifndef DUNE_TYPETREE_TRAVERSAL_HH
5 #define DUNE_TYPETREE_TRAVERSAL_HH
7 #if HAVE_RVALUE_REFERENCES
11 #include <dune/common/std/type_traits.hh>
12 #include <dune/common/std/utility.hh>
13 #include <dune/common/std/type_traits.hh>
14 #include <dune/common/hybridutilities.hh>
36 template<
bool c,
class T1,
class T2,
37 std::enable_if_t<c, int> = 0>
39 return std::forward<T1>(t1);
42 template<
bool c,
class T1,
class T2,
43 std::enable_if_t<not c, int> = 0>
45 return std::forward<T2>(t2);
49 std::enable_if_t<Tree::isLeaf, int> = 0>
52 return std::make_tuple(prefix);
56 std::enable_if_t<not Tree::isLeaf, int> = 0>
59 template<
class Tree,
TreePathType::Type pathType,
class Prefix, std::size_t... indices,
60 std::enable_if_t<(Tree::isComposite or (Tree::isPower and (pathType!=
TreePathType::dynamic))),
int> = 0>
66 template<
class Tree,
TreePathType::Type pathType,
class Prefix, std::size_t... indices,
74 std::enable_if_t<not Tree::isLeaf, int>>
77 return Detail::leafTreePathTuple<Tree, pathType>(prefix, Dune::Std::make_index_sequence<
Tree::degree()>{});
91 template<
class T,
class TreePath,
class V,
92 std::enable_if_t<std::decay_t<T>::isLeaf,
int> = 0>
101 template<
class T,
class TreePath,
class V,
102 std::enable_if_t<not std::decay_t<T>::isLeaf,
int> = 0>
109 using Tree = std::remove_reference_t<T>;
110 using Visitor = std::remove_reference_t<V>;
118 auto indices = Dune::range(
degree);
119 Dune::Hybrid::forEach(indices, [&](
auto i) {
121 auto&&
child = tree.child(i);
130 static const auto visitChild = Visitor::template VisitChild<Tree,Child,TreePath>::value;
131 Dune::Hybrid::ifElse(Dune::Std::bool_constant<visitChild>{}, [&] (
auto id) {
150 template<
class Tree,
class TreePath,
class PreFunc,
class LeafFunc,
class PostFunc>
153 using TreeType = std::decay_t<Tree>;
154 Dune::Hybrid::ifElse(Dune::Std::bool_constant<TreeType::isLeaf>{}, [&] (
auto id) {
163 Dune::Hybrid::forEach(indices, [&](
auto i) {
191 template<
class Tree, TreePathType::Type pathType=TreePathType::dynamic>
194 return Detail::leafTreePathTuple<std::decay_t<Tree>, pathType>(
hybridTreePath());
212 template<
typename Tree,
typename Visitor>
229 template<
class Tree,
class PreFunc,
class LeafFunc,
class PostFunc>
230 void forEachNode(Tree&& tree, PreFunc&& preFunc, LeafFunc&& leafFunc, PostFunc&& postFunc)
245 template<
class Tree,
class InnerFunc,
class LeafFunc>
246 void forEachNode(Tree&& tree, InnerFunc&& innerFunc, LeafFunc&& leafFunc)
248 auto nop = [](
auto&&... args) {};
261 template<
class Tree,
class NodeFunc>
276 template<
class Tree,
class LeafFunc>
279 auto nop = [](
auto&&... args) {};
288 #endif // DUNE_TYPETREE_TRAVERSAL_HH