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) {};
static const TreePathType::Type treePathType
Definition: traversalutilities.hh:30
void forEachNode(Tree &&tree, PreFunc &&preFunc, LeafFunc &&leafFunc, PostFunc &&postFunc)
Traverse tree and visit each node.
Definition: traversal.hh:230
constexpr auto leafTreePathTuple()
Create tuple of tree paths to leafs.
Definition: traversal.hh:192
void forEachLeafNode(Tree &&tree, LeafFunc &&leafFunc)
Traverse tree and visit each leaf node.
Definition: traversal.hh:277
void applyToTree(Tree &&tree, Visitor &&visitor)
Apply visitor to TypeTree.
Definition: traversal.hh:213
typename impl::_Child< Node, indices... >::type Child
Template alias for the type of a child node given by a list of child indices.
Definition: childextraction.hh:276
ImplementationDefined child(Node &&node, Indices... indices)
Extracts the child of a node given by a sequence of compile-time and run-time indices.
Definition: childextraction.hh:179
std::size_t degree(const Node &node)
Returns the degree of node as run time information.
Definition: nodeinterface.hh:71
constexpr HybridTreePath< T... > treePath(const T &... t)
Constructs a new HybridTreePath from the given indices.
Definition: treepath.hh:188
constexpr HybridTreePath< T... > hybridTreePath(const T &... t)
Constructs a new HybridTreePath from the given indices.
Definition: treepath.hh:177
constexpr HybridTreePath< T..., std::size_t > push_back(const HybridTreePath< T... > &tp, std::size_t i)
Appends a run time index to a HybridTreePath.
Definition: treepath.hh:278
HybridTreePath< Dune::index_constant< i >... > TreePath
Definition: treepath.hh:433
Definition: accumulate_static.hh:13
void forEachNode(Tree &&tree, TreePath treePath, PreFunc &&preFunc, LeafFunc &&leafFunc, PostFunc &&postFunc)
Definition: traversal.hh:151
void applyToTree(T &&tree, TreePath treePath, V &&visitor)
Definition: traversal.hh:93
constexpr auto conditionalValue(T1 &&t1, T2 &&t2)
Definition: traversal.hh:38
constexpr auto leafTreePathTuple(Prefix prefix)
Definition: traversal.hh:50
Type
Definition: treepath.hh:30
@ dynamic
Definition: treepath.hh:30
A hybrid version of TreePath that supports both compile time and run time indices.
Definition: treepath.hh:79