dune-typetree  2.7.1
traversalutilities.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 
4 #ifndef DUNE_TYPETREE_TRAVERSALUTILITIES_HH
5 #define DUNE_TYPETREE_TRAVERSALUTILITIES_HH
6 
8 
9 namespace Dune {
10  namespace TypeTree {
11 
17  namespace {
18 
20 
25  template<typename F, typename R, typename ResultType>
26  struct LeafReductionVisitor
27  : public TypeTree::TreeVisitor
28  {
29 
31 
32  template<typename Node, typename TreePath>
33  void leaf(const Node& node, TreePath treePath)
34  {
36  }
37 
38  LeafReductionVisitor(F functor, R reduction, ResultType startValue)
39  : _functor(functor)
40  , _reduction(reduction)
41  , _value(startValue)
42  {}
43 
44  ResultType result() { return _value; }
45 
48  ResultType _value;
49 
50  };
51 
52  } // anonymous namespace
53 
55 
80  template<typename ResultType, typename Tree, typename F, typename R>
81  ResultType reduceOverLeafs(const Tree& tree, F functor, R reduction, ResultType startValue)
82  {
83  LeafReductionVisitor<F,R,ResultType> visitor(functor,reduction,startValue);
84  TypeTree::applyToTree(tree,visitor);
85  return visitor.result();
86  }
87 
89 
90  } // namespace TypeTree
91 } //namespace Dune
92 
93 #endif // DUNE_TYPETREE_TRAVERSALUTILITIES_HH
Dune::TypeTree::applyToTree
void applyToTree(Tree &&tree, Visitor &&visitor)
Apply visitor to TypeTree.
Definition: traversal.hh:213
_functor
F _functor
Definition: traversalutilities.hh:46
_value
ResultType _value
Definition: traversalutilities.hh:48
Dune::TypeTree::treePath
constexpr HybridTreePath< T... > treePath(const T &... t)
Constructs a new HybridTreePath from the given indices.
Definition: treepath.hh:188
Dune::TypeTree::TreePath
HybridTreePath< Dune::index_constant< i >... > TreePath
Definition: treepath.hh:433
treePathType
static const TreePathType::Type treePathType
Definition: traversalutilities.hh:30
Dune::TypeTree::TreePathType::Type
Type
Definition: treepath.hh:30
result
static const result_type result
Definition: accumulate_static.hh:110
_reduction
R _reduction
Definition: traversalutilities.hh:47
Dune::TypeTree::TreePathType::dynamic
@ dynamic
Definition: treepath.hh:30
Dune::TypeTree::reduceOverLeafs
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
traversal.hh
Dune
Definition: accumulate_static.hh:13