4 #ifndef DUNE_TYPETREE_ACCUMULATE_STATIC_HH
5 #define DUNE_TYPETREE_ACCUMULATE_STATIC_HH
19 template<
typename result_type>
23 template<result_type r1, result_type r2>
26 static const result_type
result = r1 || r2;
31 template<
typename result_type>
34 template<result_type r1, result_type r2>
37 static const result_type
result = r1 && r2;
42 template<
typename result_type>
45 template<result_type r1, result_type r2>
48 static const result_type
result = r1 + r2;
53 template<
typename result_type>
56 template<result_type r1, result_type r2>
59 static const result_type
result = r1 - r2;
64 template<
typename result_type>
67 template<result_type r1, result_type r2>
70 static const result_type
result = r1 * r2;
75 template<
typename result_type>
78 template<result_type r1, result_type r2>
81 static const result_type
result = r1 < r2 ? r1 : r2;
86 template<
typename result_type>
89 template<result_type r1, result_type r2>
92 static const result_type
result = r1 > r2 ? r1 : r2;
102 template<
typename Node,
typename Functor,
typename Reduction,
typename Functor::result_type current_value,
typename TreePath,
bool doVisit>
103 struct accumulate_node_helper
106 typedef typename Functor::result_type result_type;
108 static const result_type
result = current_value;
113 template<
typename Node,
typename Functor,
typename Reduction,
typename Functor::result_type current_value,
typename TreePath>
114 struct accumulate_node_helper<Node,Functor,Reduction,current_value,TreePath,true>
117 typedef typename Functor::result_type result_type;
124 template<
typename Tree,
typename Functor,
typename Reduction,
typename ParentChildReduction,
typename Functor::result_type current_value,
typename TreePath,
typename Tag>
125 struct accumulate_value;
128 template<
typename LeafNode,
typename Functor,
typename Reduction,
typename ParentChildReduction,
typename Functor::result_type current_value,
typename TreePath>
129 struct accumulate_value<LeafNode,Functor,Reduction,ParentChildReduction,current_value,TreePath,LeafNodeTag>
132 typedef typename Functor::result_type result_type;
134 static const result_type
result =
141 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>
142 struct accumulate_over_children
145 typedef typename Functor::result_type result_type;
147 typedef typename TreePathPushBack<TreePath,i>::type child_tree_path;
158 template<
typename Node,
typename Functor,
typename Reduction,
typename ParentChildReduction,
typename Functor::result_type current_value,
typename TreePath, std::
size_t n>
159 struct accumulate_over_children<Node,Functor,Reduction,ParentChildReduction,current_value,TreePath,n,n>
162 typedef typename Functor::result_type result_type;
164 static const result_type
result = current_value;
170 template<
typename Node,
typename Functor,
typename Reduction,
typename ParentChildReduction,
typename Functor::result_type current_value,
typename TreePath>
171 struct accumulate_value_generic_composite_node
174 typedef typename Functor::result_type result_type;
178 static const result_type
result =
185 template<
typename PowerNode,
typename Functor,
typename Reduction,
typename ParentChildReduction,
typename Functor::result_type current_value,
typename TreePath>
186 struct accumulate_value<PowerNode,Functor,Reduction,ParentChildReduction,current_value,TreePath,PowerNodeTag>
187 :
public accumulate_value_generic_composite_node<PowerNode,Functor,Reduction,ParentChildReduction,current_value,TreePath>
191 template<
typename CompositeNode,
typename Functor,
typename Reduction,
typename ParentChildReduction,
typename Functor::result_type current_value,
typename TreePath>
192 struct accumulate_value<CompositeNode,Functor,Reduction,ParentChildReduction,current_value,TreePath,CompositeNodeTag>
193 :
public accumulate_value_generic_composite_node<CompositeNode,Functor,Reduction,ParentChildReduction,current_value,TreePath>
196 #if HAVE_VARIADIC_TEMPLATES
199 template<
typename VariadicCompositeNode,
typename Functor,
typename Reduction,
typename ParentChildReduction,
typename Functor::result_type current_value,
typename TreePath>
200 struct accumulate_value<VariadicCompositeNode,Functor,Reduction,ParentChildReduction,current_value,TreePath,VariadicCompositeNodeTag>
201 :
public accumulate_value_generic_composite_node<VariadicCompositeNode,Functor,Reduction,ParentChildReduction,current_value,TreePath>
204 #endif // HAVE_VARIADIC_TEMPLATES
265 template<
typename Tree,
typename Functor,
typename Reduction,
typename Functor::result_type startValue,
typename ParentChildReduction = Reduction>
273 static const result_type result = accumulate_value<Tree,Functor,Reduction,ParentChildReduction,startValue,TreePath<>,
typename Tree::NodeTag>
::result;
279 struct flattened_reduction;
283 struct bottom_up_reduction;
291 template<
typename Node,
typename Functor,
typename Reduction,
typename current_type,
typename TreePath,
bool doVisit>
292 struct accumulate_type_node_helper
295 typedef current_type type;
300 template<
typename Node,
typename Functor,
typename Reduction,
typename current_type,
typename TreePath>
301 struct accumulate_type_node_helper<Node,Functor,Reduction,current_type,TreePath,true>
304 typedef typename Reduction::template reduce<
306 typename Functor::template visit<
315 template<
typename Tree,
typename Policy,
typename current_type,
typename TreePath,
typename Tag>
316 struct accumulate_type;
319 template<
typename LeafNode,
typename Policy,
typename current_type,
typename TreePath>
320 struct accumulate_type<LeafNode,Policy,current_type,TreePath,LeafNodeTag>
323 typedef typename accumulate_type_node_helper<
325 typename Policy::functor,
326 typename Policy::sibling_reduction,
329 Policy::functor::template doVisit<
339 template<
typename current_type,
typename tree_path,
typename start_type,
typename reduction_strategy>
340 struct propagate_type_down_tree;
343 template<
typename current_type,
typename tree_path,
typename start_type>
344 struct propagate_type_down_tree<
351 typedef current_type type;
355 template<
typename current_type,
typename tree_path,
typename start_type>
356 struct propagate_type_down_tree<
363 typedef typename Dune::conditional<
372 template<
typename Node,
typename Policy,
typename current_type,
typename TreePath, std::
size_t i, std::
size_t n>
373 struct accumulate_type_over_children
376 typedef typename TreePathPushBack<TreePath,i>::type child_tree_path;
380 typedef typename accumulate_type<
384 typename propagate_type_down_tree<
387 typename Policy::start_type,
388 typename Policy::reduction_strategy
391 typename child::NodeTag
392 >::type child_result_type;
394 typedef typename accumulate_type_over_children<
406 template<
typename Node,
typename Policy,
typename current_type,
typename TreePath, std::
size_t n>
407 struct accumulate_type_over_children<Node,Policy,current_type,TreePath,n,n>
410 typedef current_type type;
417 template<
typename Node,
typename Policy,
typename current_type,
typename TreePath>
418 struct accumulate_type_generic_composite_node
421 typedef typename accumulate_type_over_children<
428 >::type children_result_type;
430 typedef typename accumulate_type_node_helper<
432 typename Policy::functor,
433 typename Policy::parent_child_reduction,
434 children_result_type,
436 Policy::functor::template doVisit<
445 template<
typename PowerNode,
typename Policy,
typename current_type,
typename TreePath>
446 struct accumulate_type<PowerNode,Policy,current_type,TreePath,PowerNodeTag>
447 :
public accumulate_type_generic_composite_node<PowerNode,Policy,current_type,TreePath>
451 template<
typename CompositeNode,
typename Policy,
typename current_type,
typename TreePath>
452 struct accumulate_type<CompositeNode,Policy,current_type,TreePath,CompositeNodeTag>
453 :
public accumulate_type_generic_composite_node<CompositeNode,Policy,current_type,TreePath>
456 #if HAVE_VARIADIC_TEMPLATES
459 template<
typename VariadicCompositeNode,
typename Policy,
typename current_type,
typename TreePath>
460 struct accumulate_type<VariadicCompositeNode,Policy,current_type,TreePath,VariadicCompositeNodeTag>
461 :
public accumulate_type_generic_composite_node<VariadicCompositeNode,Policy,current_type,TreePath>
464 #endif // HAVE_VARIADIC_TEMPLATES
480 typename ParentChildReduction = Reduction,
481 typename ReductionAlgorithm = flattened_reduction
569 template<
typename Tree,
typename Policy>
574 typedef typename accumulate_type<
577 typename Policy::start_type,
579 typename Tree::NodeTag
590 #endif // DUNE_TYPETREE_ACCUMULATE_STATIC_HH
Definition: accumulate_static.hh:46
Definition: treepath.hh:32
Statically combine two values of type result_type using ||.
Definition: accumulate_static.hh:21
Statically accumulate a type over the nodes of a TypeTree.
Definition: accumulate_static.hh:570
static const result_type result
Definition: accumulate_static.hh:48
static const result_type result
Definition: accumulate_static.hh:70
Definition: accumulate_static.hh:35
Definition: accumulate_static.hh:90
static const result_type result
Definition: accumulate_static.hh:37
static const result_type result
Definition: accumulate_static.hh:92
Functor functor
Definition: accumulate_static.hh:513
static const result_type result
Definition: accumulate_static.hh:81
static const result_type result
Definition: accumulate_static.hh:108
Statically combine two values of type result_type by returning their maximum.
Definition: accumulate_static.hh:87
ReductionAlgorithm reduction_strategy
Definition: accumulate_static.hh:556
Definition: accumulate_static.hh:57
ParentChildReduction parent_child_reduction
Definition: accumulate_static.hh:542
accumulate_type< Tree, Policy, typename Policy::start_type, TreePath<>, typename Tree::NodeTag >::type type
The accumulated result of the computation.
Definition: accumulate_static.hh:580
Statically combine two values of type result_type using -.
Definition: accumulate_static.hh:54
StartType start_type
Definition: accumulate_static.hh:550
Definition: accumulate_static.hh:483
Definition: accumulate_static.hh:24
Statically combine two values of type result_type using +.
Definition: accumulate_static.hh:43
Reduction sibling_reduction
Definition: accumulate_static.hh:534
Definition: accumulate_static.hh:68
Statically combine two values of type result_type using &&.
Definition: accumulate_static.hh:32
static const std::size_t value
Definition: compositenode.hh:38
static const result_type result
The accumulated result of the computation.
Definition: accumulate_static.hh:273
Functor::result_type result_type
The result type of the computation.
Definition: accumulate_static.hh:270
Statically combine two values of type result_type using *.
Definition: accumulate_static.hh:65
Statically combine two values of type result_type by returning their minimum.
Definition: accumulate_static.hh:76
static const result_type child_result
Definition: accumulate_static.hh:151
static const result_type result
Definition: accumulate_static.hh:59
Statically accumulate a value over the nodes of a TypeTree.
Definition: accumulate_static.hh:266
Type
Definition: treepath.hh:26
static const result_type result
Definition: accumulate_static.hh:26
Definition: accumulate_static.hh:79