4 #ifndef DUNE_TYPETREE_ACCUMULATE_STATIC_HH 5 #define DUNE_TYPETREE_ACCUMULATE_STATIC_HH 7 #include <dune/common/typetraits.hh> 21 template<
typename result_type>
25 template<result_type r1, result_type r2>
28 static const result_type
result = r1 || r2;
33 template<
typename result_type>
36 template<result_type r1, result_type r2>
39 static const result_type
result = r1 && r2;
44 template<
typename result_type>
47 template<result_type r1, result_type r2>
50 static const result_type
result = r1 + r2;
55 template<
typename result_type>
58 template<result_type r1, result_type r2>
61 static const result_type
result = r1 - r2;
66 template<
typename result_type>
69 template<result_type r1, result_type r2>
72 static const result_type
result = r1 * r2;
77 template<
typename result_type>
80 template<result_type r1, result_type r2>
83 static const result_type
result = r1 < r2 ? r1 : r2;
88 template<
typename result_type>
91 template<result_type r1, result_type r2>
94 static const result_type
result = r1 > r2 ? r1 : r2;
104 template<
typename Node,
typename Functor,
typename Reduction,
typename Functor::result_type current_value,
typename TreePath,
bool doVisit>
105 struct accumulate_node_helper
108 typedef typename Functor::result_type result_type;
110 static const result_type
result = current_value;
115 template<
typename Node,
typename Functor,
typename Reduction,
typename Functor::result_type current_value,
typename TreePath>
116 struct accumulate_node_helper<Node,Functor,Reduction,current_value,TreePath,true>
119 typedef typename Functor::result_type result_type;
126 template<
typename Tree,
typename Functor,
typename Reduction,
typename ParentChildReduction,
typename Functor::result_type current_value,
typename TreePath,
typename Tag>
127 struct accumulate_value;
130 template<
typename LeafNode,
typename Functor,
typename Reduction,
typename ParentChildReduction,
typename Functor::result_type current_value,
typename TreePath>
131 struct accumulate_value<LeafNode,Functor,Reduction,ParentChildReduction,current_value,TreePath,LeafNodeTag>
134 typedef typename Functor::result_type result_type;
136 static const result_type
result =
138 accumulate_node_helper<LeafNode,Functor,Reduction,current_value,TreePath,Functor::template doVisit<LeafNode,TreePath>::value>
::result;
143 template<
typename Node,
typename Functor,
typename Reduction,
typename ParentChildReduction,
typename Functor::result_type current_value,
typename TreePath, std::
size_t i, std::
size_t n>
144 struct accumulate_over_children
147 typedef typename Functor::result_type result_type;
149 typedef typename TreePathPushBack<TreePath,i>::type child_tree_path;
153 static const result_type
child_result = accumulate_value<child,Functor,Reduction,ParentChildReduction,current_value,child_tree_path,NodeTag<child>>
::result;
160 template<
typename Node,
typename Functor,
typename Reduction,
typename ParentChildReduction,
typename Functor::result_type current_value,
typename TreePath, std::
size_t n>
161 struct accumulate_over_children<Node,Functor,Reduction,ParentChildReduction,current_value,TreePath,n,n>
164 typedef typename Functor::result_type result_type;
166 static const result_type
result = current_value;
172 template<
typename Node,
typename Functor,
typename Reduction,
typename ParentChildReduction,
typename Functor::result_type current_value,
typename TreePath>
173 struct accumulate_value_generic_composite_node
176 typedef typename Functor::result_type result_type;
178 static const result_type
child_result = accumulate_over_children<Node,Functor,Reduction,ParentChildReduction,current_value,TreePath,0,StaticDegree<Node>::value>
::result;
180 static const result_type
result =
181 accumulate_node_helper<Node,Functor,ParentChildReduction,child_result,TreePath,Functor::template doVisit<Node,TreePath>::value>
::result;
187 template<
typename PowerNode,
typename Functor,
typename Reduction,
typename ParentChildReduction,
typename Functor::result_type current_value,
typename TreePath>
188 struct accumulate_value<PowerNode,Functor,Reduction,ParentChildReduction,current_value,TreePath,PowerNodeTag>
189 :
public accumulate_value_generic_composite_node<PowerNode,Functor,Reduction,ParentChildReduction,current_value,TreePath>
193 template<
typename CompositeNode,
typename Functor,
typename Reduction,
typename ParentChildReduction,
typename Functor::result_type current_value,
typename TreePath>
194 struct accumulate_value<CompositeNode,Functor,Reduction,ParentChildReduction,current_value,TreePath,CompositeNodeTag>
195 :
public accumulate_value_generic_composite_node<CompositeNode,Functor,Reduction,ParentChildReduction,current_value,TreePath>
257 template<
typename Tree,
typename Functor,
typename Reduction,
typename Functor::result_type startValue,
typename ParentChildReduction = Reduction>
271 struct flattened_reduction;
275 struct bottom_up_reduction;
283 template<
typename Node,
typename Functor,
typename Reduction,
typename current_type,
typename TreePath,
bool doVisit>
284 struct accumulate_type_node_helper
287 typedef current_type type;
292 template<
typename Node,
typename Functor,
typename Reduction,
typename current_type,
typename TreePath>
293 struct accumulate_type_node_helper<Node,Functor,Reduction,current_type,
TreePath,true>
296 typedef typename Reduction::template reduce<
298 typename Functor::template visit<
307 template<
typename Tree,
typename Policy,
typename current_type,
typename TreePath,
typename Tag>
308 struct accumulate_type;
311 template<
typename LeafNode,
typename Policy,
typename current_type,
typename TreePath>
315 typedef typename accumulate_type_node_helper<
317 typename Policy::functor,
318 typename Policy::sibling_reduction,
321 Policy::functor::template doVisit<
331 template<
typename current_type,
typename tree_path,
typename start_type,
typename reduction_strategy>
332 struct propagate_type_down_tree;
335 template<
typename current_type,
typename tree_path,
typename start_type>
336 struct propagate_type_down_tree<
343 typedef current_type type;
347 template<
typename current_type,
typename tree_path,
typename start_type>
348 struct propagate_type_down_tree<
355 typedef typename std::conditional<
364 template<
typename Node,
typename Policy,
typename current_type,
typename TreePath, std::
size_t i, std::
size_t n>
365 struct accumulate_type_over_children
372 typedef typename accumulate_type<
376 typename propagate_type_down_tree<
379 typename Policy::start_type,
380 typename Policy::reduction_strategy
384 >::type child_result_type;
386 typedef typename accumulate_type_over_children<
398 template<
typename Node,
typename Policy,
typename current_type,
typename TreePath, std::
size_t n>
399 struct accumulate_type_over_children<Node,Policy,current_type,
TreePath,n,n>
402 typedef current_type type;
409 template<
typename Node,
typename Policy,
typename current_type,
typename TreePath>
410 struct accumulate_type_generic_composite_node
413 typedef typename accumulate_type_over_children<
420 >::type children_result_type;
422 typedef typename accumulate_type_node_helper<
424 typename Policy::functor,
425 typename Policy::parent_child_reduction,
426 children_result_type,
428 Policy::functor::template doVisit<
437 template<
typename PowerNode,
typename Policy,
typename current_type,
typename TreePath>
439 :
public accumulate_type_generic_composite_node<PowerNode,Policy,current_type,TreePath>
443 template<
typename CompositeNode,
typename Policy,
typename current_type,
typename TreePath>
445 :
public accumulate_type_generic_composite_node<CompositeNode,Policy,current_type,TreePath>
462 typename ParentChildReduction = Reduction,
463 typename ReductionAlgorithm = flattened_reduction
551 template<
typename Tree,
typename Policy>
556 typedef typename accumulate_type<
559 typename Policy::start_type,
572 #endif // DUNE_TYPETREE_ACCUMULATE_STATIC_HH 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
Statically combine two values of type result_type using +.
Definition: accumulate_static.hh:45
Tag designating a composite node.
Definition: nodetags.hh:22
Functor functor
Definition: accumulate_static.hh:495
Definition: accumulate_static.hh:26
Statically accumulate a value over the nodes of a TypeTree.
Definition: accumulate_static.hh:258
ParentChildReduction parent_child_reduction
Definition: accumulate_static.hh:524
Definition: accumulate_static.hh:70
Collect k instances of type T within a dune-typetree.
Definition: powernode.hh:91
Statically combine two values of type result_type using -.
Definition: accumulate_static.hh:56
Definition: accumulate_static.hh:37
Tag designating a power node.
Definition: nodetags.hh:19
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:307
Definition: accumulate_static.hh:13
Definition: treepath.hh:75
Definition: accumulate_static.hh:465
Definition: accumulate_static.hh:81
Statically combine two values of type result_type using *.
Definition: accumulate_static.hh:67
Functor::result_type result_type
The result type of the computation.
Definition: accumulate_static.hh:262
static const result_type result
Definition: accumulate_static.hh:28
Statically accumulate a type over the nodes of a TypeTree.
Definition: accumulate_static.hh:552
Statically combine two values of type result_type by returning their maximum.
Definition: accumulate_static.hh:89
Reduction sibling_reduction
Definition: accumulate_static.hh:516
Statically combine two values of type result_type using ||.
Definition: accumulate_static.hh:23
Base class for leaf nodes in a dune-typetree.
Definition: leafnode.hh:24
accumulate_type< Tree, Policy, typename Policy::start_type, TreePath<>, NodeTag< Tree > >::type type
The accumulated result of the computation.
Definition: accumulate_static.hh:562
static const result_type result
Definition: accumulate_static.hh:110
static const result_type child_result
Definition: accumulate_static.hh:153
Definition: accumulate_static.hh:48
Statically combine two values of type result_type using &&.
Definition: accumulate_static.hh:34
std::integral_constant< std::size_t, degree(static_cast< std::decay_t< Node > * >(nullptr), NodeTag< std::decay_t< Node > >()) > StaticDegree
Returns the statically known degree of the given Node type as a std::integral_constant.
Definition: nodeinterface.hh:105
Tag designating a leaf node.
Definition: nodetags.hh:16
ReductionAlgorithm reduction_strategy
Definition: accumulate_static.hh:538
Statically combine two values of type result_type by returning their minimum.
Definition: accumulate_static.hh:78
Definition: treepath.hh:57
Definition: accumulate_static.hh:59
StartType start_type
Definition: accumulate_static.hh:532
Definition: treepath.hh:30
Base class for composite nodes based on variadic templates.
Definition: compositenode.hh:23
Definition: accumulate_static.hh:92
typename std::decay_t< Node >::NodeTag NodeTag
Returns the node tag of the given Node.
Definition: nodeinterface.hh:62
Type
Definition: treepath.hh:26