4#ifndef DUNE_TYPETREE_TRAVERSALUTILITIES_HH
5#define DUNE_TYPETREE_TRAVERSALUTILITIES_HH
7#include <dune/typetree/traversal.hh>
25 template<
typename F,
typename R,
typename ResultType>
26 struct LeafReductionVisitor
27 :
public TypeTree::TreeVisitor
30 static const TreePathType::Type treePathType = TreePathType::dynamic;
32 template<
typename Node,
typename TreePath>
33 void leaf(
const Node& node, TreePath
treePath)
35 _value = _reduction(_value,_functor(node,
treePath));
38 LeafReductionVisitor(F functor, R reduction, ResultType startValue)
40 , _reduction(reduction)
44 ResultType result() {
return _value; }
80 template<
typename ResultType,
typename Tree,
typename F,
typename R>
81 ResultType
reduceOverLeafs(
const Tree& tree, F functor, R reduction, ResultType startValue)
83 LeafReductionVisitor<F,R,ResultType> visitor(functor,reduction,startValue);
85 return visitor.result();
constexpr HybridTreePath< T... > treePath(const T &... t)
Constructs a new HybridTreePath from the given indices.
Definition: treepath.hh:188
ResultType reduceOverLeafs(const Tree &tree, F functor, R reduction, ResultType startValue)
Calculate a quantity as a reduction over the leaf nodes of a TypeTree.
Definition: traversalutilities.hh:81
void applyToTree(Tree &&tree, Visitor &&visitor)
Apply visitor to TypeTree.
Definition: traversal.hh:237