4 #ifndef DUNE_TYPETREE_ACCUMULATE_STATIC_HH
5 #define DUNE_TYPETREE_ACCUMULATE_STATIC_HH
7 #include <dune/common/typetraits.hh>
20 template<
typename result_type>
24 template<result_type r1, result_type r2>
27 static const result_type
result = r1 || r2;
32 template<
typename result_type>
35 template<result_type r1, result_type r2>
38 static const result_type
result = r1 && r2;
43 template<
typename result_type>
46 template<result_type r1, result_type r2>
49 static const result_type
result = r1 + r2;
54 template<
typename result_type>
57 template<result_type r1, result_type r2>
60 static const result_type
result = r1 - r2;
65 template<
typename result_type>
68 template<result_type r1, result_type r2>
71 static const result_type
result = r1 * r2;
76 template<
typename result_type>
79 template<result_type r1, result_type r2>
82 static const result_type
result = r1 < r2 ? r1 : r2;
87 template<
typename result_type>
90 template<result_type r1, result_type r2>
93 static const result_type
result = r1 > r2 ? r1 : r2;
103 template<
typename Node,
typename Functor,
typename Reduction,
typename Functor::result_type current_value,
typename TreePath,
bool doVisit>
104 struct accumulate_node_helper
107 typedef typename Functor::result_type result_type;
109 static const result_type
result = current_value;
114 template<
typename Node,
typename Functor,
typename Reduction,
typename Functor::result_type current_value,
typename TreePath>
115 struct accumulate_node_helper<Node,Functor,Reduction,current_value,TreePath,true>
118 typedef typename Functor::result_type result_type;
125 template<
typename Tree,
typename Functor,
typename Reduction,
typename ParentChildReduction,
typename Functor::result_type current_value,
typename TreePath,
typename Tag>
126 struct accumulate_value;
129 template<
typename LeafNode,
typename Functor,
typename Reduction,
typename ParentChildReduction,
typename Functor::result_type current_value,
typename TreePath>
130 struct accumulate_value<LeafNode,Functor,Reduction,ParentChildReduction,current_value,TreePath,LeafNodeTag>
133 typedef typename Functor::result_type result_type;
135 static const result_type
result =
137 accumulate_node_helper<LeafNode,Functor,Reduction,current_value,TreePath,Functor::template doVisit<LeafNode,TreePath>::value>
::result;
142 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>
143 struct accumulate_over_children
146 typedef typename Functor::result_type result_type;
148 typedef typename TreePathPushBack<TreePath,i>::type child_tree_path;
159 template<
typename Node,
typename Functor,
typename Reduction,
typename ParentChildReduction,
typename Functor::result_type current_value,
typename TreePath, std::
size_t n>
160 struct accumulate_over_children<Node,Functor,Reduction,ParentChildReduction,current_value,TreePath,n,n>
163 typedef typename Functor::result_type result_type;
165 static const result_type
result = current_value;
171 template<
typename Node,
typename Functor,
typename Reduction,
typename ParentChildReduction,
typename Functor::result_type current_value,
typename TreePath>
172 struct accumulate_value_generic_composite_node
175 typedef typename Functor::result_type result_type;
179 static const result_type
result =
180 accumulate_node_helper<Node,Functor,ParentChildReduction,child_result,TreePath,Functor::template doVisit<Node,TreePath>::value>
::result;
186 template<
typename PowerNode,
typename Functor,
typename Reduction,
typename ParentChildReduction,
typename Functor::result_type current_value,
typename TreePath>
187 struct accumulate_value<PowerNode,Functor,Reduction,ParentChildReduction,current_value,TreePath,PowerNodeTag>
188 :
public accumulate_value_generic_composite_node<PowerNode,Functor,Reduction,ParentChildReduction,current_value,TreePath>
192 template<
typename CompositeNode,
typename Functor,
typename Reduction,
typename ParentChildReduction,
typename Functor::result_type current_value,
typename TreePath>
193 struct accumulate_value<CompositeNode,Functor,Reduction,ParentChildReduction,current_value,TreePath,CompositeNodeTag>
194 :
public accumulate_value_generic_composite_node<CompositeNode,Functor,Reduction,ParentChildReduction,current_value,TreePath>
256 template<
typename Tree,
typename Functor,
typename Reduction,
typename Functor::result_type startValue,
typename ParentChildReduction = Reduction>
264 static const result_type
result = accumulate_value<Tree,Functor,Reduction,ParentChildReduction,startValue,TreePath<>,
typename Tree::NodeTag>
::result;
270 struct flattened_reduction;
274 struct bottom_up_reduction;
282 template<
typename Node,
typename Functor,
typename Reduction,
typename current_type,
typename TreePath,
bool doVisit>
283 struct accumulate_type_node_helper
286 typedef current_type type;
291 template<
typename Node,
typename Functor,
typename Reduction,
typename current_type,
typename TreePath>
292 struct accumulate_type_node_helper<Node,Functor,Reduction,current_type,TreePath,true>
295 typedef typename Reduction::template reduce<
297 typename Functor::template visit<
306 template<
typename Tree,
typename Policy,
typename current_type,
typename TreePath,
typename Tag>
307 struct accumulate_type;
310 template<
typename LeafNode,
typename Policy,
typename current_type,
typename TreePath>
311 struct accumulate_type<LeafNode,Policy,current_type,TreePath,LeafNodeTag>
314 typedef typename accumulate_type_node_helper<
316 typename Policy::functor,
317 typename Policy::sibling_reduction,
320 Policy::functor::template doVisit<
330 template<
typename current_type,
typename tree_path,
typename start_type,
typename reduction_strategy>
331 struct propagate_type_down_tree;
334 template<
typename current_type,
typename tree_path,
typename start_type>
335 struct propagate_type_down_tree<
342 typedef current_type type;
346 template<
typename current_type,
typename tree_path,
typename start_type>
347 struct propagate_type_down_tree<
354 typedef typename Dune::conditional<
355 TreePathBack<tree_path>::value == 0,
363 template<
typename Node,
typename Policy,
typename current_type,
typename TreePath, std::
size_t i, std::
size_t n>
364 struct accumulate_type_over_children
367 typedef typename TreePathPushBack<TreePath,i>::type child_tree_path;
371 typedef typename accumulate_type<
375 typename propagate_type_down_tree<
378 typename Policy::start_type,
379 typename Policy::reduction_strategy
382 typename child::NodeTag
383 >::type child_result_type;
385 typedef typename accumulate_type_over_children<
397 template<
typename Node,
typename Policy,
typename current_type,
typename TreePath, std::
size_t n>
398 struct accumulate_type_over_children<Node,Policy,current_type,TreePath,n,n>
401 typedef current_type type;
408 template<
typename Node,
typename Policy,
typename current_type,
typename TreePath>
409 struct accumulate_type_generic_composite_node
412 typedef typename accumulate_type_over_children<
419 >::type children_result_type;
421 typedef typename accumulate_type_node_helper<
423 typename Policy::functor,
424 typename Policy::parent_child_reduction,
425 children_result_type,
427 Policy::functor::template doVisit<
436 template<
typename PowerNode,
typename Policy,
typename current_type,
typename TreePath>
437 struct accumulate_type<PowerNode,Policy,current_type,TreePath,PowerNodeTag>
438 :
public accumulate_type_generic_composite_node<PowerNode,Policy,current_type,TreePath>
442 template<
typename CompositeNode,
typename Policy,
typename current_type,
typename TreePath>
443 struct accumulate_type<CompositeNode,Policy,current_type,TreePath,CompositeNodeTag>
444 :
public accumulate_type_generic_composite_node<CompositeNode,Policy,current_type,TreePath>
461 typename ParentChildReduction = Reduction,
462 typename ReductionAlgorithm = flattened_reduction
550 template<
typename Tree,
typename Policy>
555 typedef typename accumulate_type<
558 typename Policy::start_type,
560 typename Tree::NodeTag
571 #endif // DUNE_TYPETREE_ACCUMULATE_STATIC_HH
static const result_type child_result
Definition: accumulate_static.hh:152
static const result_type result
Definition: accumulate_static.hh:82
static const result_type result
Definition: accumulate_static.hh:71
Statically accumulate a type over the nodes of a TypeTree.
Definition: accumulate_static.hh:551
Functor functor
Definition: accumulate_static.hh:494
Statically combine two values of type result_type using -.
Definition: accumulate_static.hh:55
static const result_type result
Definition: accumulate_static.hh:60
Definition: accumulate_static.hh:12
Definition: accumulate_static.hh:464
Definition: accumulate_static.hh:36
Statically combine two values of type result_type using ||.
Definition: accumulate_static.hh:22
Definition: accumulate_static.hh:91
static const result_type result
Definition: accumulate_static.hh:93
Definition: accumulate_static.hh:80
Statically combine two values of type result_type by returning their minimum.
Definition: accumulate_static.hh:77
Definition: accumulate_static.hh:47
Definition: accumulate_static.hh:69
Statically combine two values of type result_type by returning their maximum.
Definition: accumulate_static.hh:88
accumulate_type< Tree, Policy, typename Policy::start_type, TreePath<>, typename Tree::NodeTag >::type type
The accumulated result of the computation.
Definition: accumulate_static.hh:561
StartType start_type
Definition: accumulate_static.hh:531
Type
Definition: treepath.hh:25
Statically combine two values of type result_type using +.
Definition: accumulate_static.hh:44
ReductionAlgorithm reduction_strategy
Definition: accumulate_static.hh:537
static const result_type result
Definition: accumulate_static.hh:27
Reduction sibling_reduction
Definition: accumulate_static.hh:515
Statically combine two values of type result_type using &&.
Definition: accumulate_static.hh:33
Statically combine two values of type result_type using *.
Definition: accumulate_static.hh:66
static const result_type result
Definition: accumulate_static.hh:38
Definition: accumulate_static.hh:58
static const result_type result
The accumulated result of the computation.
Definition: accumulate_static.hh:264
Functor::result_type result_type
The result type of the computation.
Definition: accumulate_static.hh:261
Definition: accumulate_static.hh:25
static const result_type result
Definition: accumulate_static.hh:109
Statically accumulate a value over the nodes of a TypeTree.
Definition: accumulate_static.hh:257
Definition: treepath.hh:29
static const result_type result
Definition: accumulate_static.hh:49
ParentChildReduction parent_child_reduction
Definition: accumulate_static.hh:523