dune-typetree 2.10
Loading...
Searching...
No Matches
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// SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root
4// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-GPL-2.0-only-with-PDELab-exception
5
6#ifndef DUNE_TYPETREE_TRAVERSALUTILITIES_HH
7#define DUNE_TYPETREE_TRAVERSALUTILITIES_HH
8
10
11namespace Dune {
12 namespace TypeTree {
13
19 namespace {
20
22
27 template<typename F, typename R, typename ResultType>
28 struct LeafReductionVisitor
29 : public TypeTree::TreeVisitor
30 {
31
33
34 template<typename Node, typename TreePath>
35 void leaf(const Node& node, TreePath treePath)
36 {
38 }
39
40 LeafReductionVisitor(F functor, R reduction, ResultType startValue)
41 : _functor(functor)
42 , _reduction(reduction)
43 , _value(startValue)
44 {}
45
46 ResultType result() { return _value; }
47
50 ResultType _value;
51
52 };
53
54 } // anonymous namespace
55
57
82 template<typename ResultType, typename Tree, typename F, typename R>
83 ResultType reduceOverLeafs(const Tree& tree, F functor, R reduction, ResultType startValue)
84 {
85 LeafReductionVisitor<F,R,ResultType> visitor(functor,reduction,startValue);
86 TypeTree::applyToTree(tree,visitor);
87 return visitor.result();
88 }
89
91
92 } // namespace TypeTree
93} //namespace Dune
94
95#endif // DUNE_TYPETREE_TRAVERSALUTILITIES_HH
static const result_type result
Definition accumulate_static.hh:113
R _reduction
Definition traversalutilities.hh:49
F _functor
Definition traversalutilities.hh:48
static const TreePathType::Type treePathType
Definition traversalutilities.hh:32
ResultType _value
Definition traversalutilities.hh:50
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:83
void applyToTree(Tree &&tree, Visitor &&visitor)
Apply visitor to TypeTree.
Definition traversal.hh:239
constexpr auto treePath(const T &... t)
Constructs a new HybridTreePath from the given indices.
Definition treepath.hh:326
Definition accumulate_static.hh:16
Type
Definition treepath.hh:106
@ dynamic
Definition treepath.hh:106