4#ifndef DUNE_TYPETREE_UTILITY_HH
5#define DUNE_TYPETREE_UTILITY_HH
12#include <dune/common/shared_ptr.hh>
13#include <dune/common/indices.hh>
27 std::shared_ptr<T> convert_arg(
const T& t)
29 return std::make_shared<T>(t);
33 std::shared_ptr<T> convert_arg(T& t)
35 return stackobject_to_shared_ptr(t);
38 template<
typename BaseType,
typename T>
39 T& assertGridViewType(T& t)
41 static_assert((std::is_same<
typename BaseType::Traits::GridViewType,
42 typename T::Traits::GridViewType>::value),
43 "GridViewType must be equal in all components of composite type");
49 typename std::enable_if<!std::is_lvalue_reference<T>::value,std::shared_ptr<T> >::type convert_arg(T&& t)
51 return std::make_shared<T>(std::forward<T>(t));
64 template<
typename Tree,
typename Tag = StartTag>
94 template<
typename Node>
98 static const std::size_t
depth = 1;
108 template<
typename Node>
109 struct TreeInfo<Node,PowerNodeTag>
112 typedef TreeInfo<typename Node::ChildType,NodeTag<typename Node::ChildType>> ChildInfo;
114 static const std::size_t
depth = 1 + ChildInfo::depth;
116 static const std::size_t
nodeCount = 1 + StaticDegree<Node>::value * ChildInfo::nodeCount;
118 static const std::size_t
leafCount = StaticDegree<Node>::value * ChildInfo::leafCount;
127 template<
typename Node, std::
size_t k, std::
size_t n>
128 struct generic_compositenode_children_info
131 typedef generic_compositenode_children_info<Node,k+1,n> NextChild;
134 typedef typename Node::template Child<k>::Type Child;
135 typedef NodeTag<Child> ChildTag;
136 typedef TreeInfo<Child,ChildTag> ChildInfo;
139 static const std::size_t maxDepth = ChildInfo::depth > NextChild::maxDepth ? ChildInfo::depth : NextChild::maxDepth;
141 static const std::size_t nodeCount = ChildInfo::nodeCount + NextChild::nodeCount;
143 static const std::size_t leafCount = ChildInfo::leafCount + NextChild::leafCount;
148 template<
typename Node, std::
size_t n>
149 struct generic_compositenode_children_info<Node,n,n>
151 static const std::size_t maxDepth = 0;
153 static const std::size_t nodeCount = 0;
155 static const std::size_t leafCount = 0;
162 template<
typename Node>
163 struct GenericCompositeNodeInfo
166 typedef generic_compositenode_children_info<Node,0,StaticDegree<Node>::value> Children;
168 static const std::size_t depth = 1 + Children::maxDepth;
170 static const std::size_t nodeCount = 1 + Children::nodeCount;
172 static const std::size_t leafCount = Children::leafCount;
178 template<
typename Node>
179 struct TreeInfo<Node,CompositeNodeTag>
180 :
public GenericCompositeNodeInfo<Node>
206 template<std::size_t... i>
210 template<std::size_t n, std::size_t... i>
225 template<std::size_t... i>
234 template<
typename tuple>
240 template<
typename tuple>
251 template<std::
size_t n>
257 using Dune::index_constant;
258 namespace Indices = Dune::Indices;
264 template<
typename... Args>
269 namespace apply_to_tuple_policy {
285 template<
typename T,
typename F, std::size_t... i>
288 discard((f(std::get<i>(std::forward<T>(t))),0)...);
292 template<
typename T,
typename F, std::size_t... i>
293 void _apply_to_tuple(T&& t, F&& f, std::index_sequence<i...>,apply_to_tuple_policy::pass_index)
295 discard((f(index_constant<i>{},std::get<i>(std::forward<T>(t))),0)...);
308 template<
typename T,
typename F,
typename Policy>
311 const std::size_t size = std::tuple_size<typename std::decay<T>::type>::value;
315 std::make_index_sequence<size>{},
tuple_index_pack_builder< tuple >::type tuple_indices(const tuple &t)
Generate an index_pack for the tuple t.
Definition utility.hh:241
void apply_to_tuple(T &&t, F &&f, Policy=apply_to_tuple_policy::default_policy())
Apply a functor to each element of a std::tuple.
Definition utility.hh:309
void discard(Args &&... args)
No-op function to make calling a function on a variadic template argument pack legal C++.
Definition utility.hh:265
index_pack_builder< n >::type index_range(std::integral_constant< std::size_t, n >={})
Generate an index_pack with the values {0, 1, ..., n-1}.
Definition utility.hh:252
Definition accumulate_static.hh:13
no_pass_index default_policy
Default policy.
Definition utility.hh:278
Tag designating a leaf node.
Definition nodetags.hh:16
Struct for obtaining some basic structural information about a TypeTree.
Definition utility.hh:66
static const std::size_t leafCount
The number of leaf nodes in the TypeTree.
Definition utility.hh:81
static const std::size_t depth
The depth of the TypeTree.
Definition utility.hh:75
static const std::size_t nodeCount
The total number of nodes in the TypeTree.
Definition utility.hh:78
Simple holder class for a template argument pack of indices.
Definition utility.hh:207
TMP to build an index_pack containing the sequence 0,...,n-1.
Definition utility.hh:213
index_pack< 0, 1,..., n-1 > type
Result.
Definition utility.hh:217
TMP to build an index_pack for all elements in the tuple.
Definition utility.hh:237
Do not pass the index of the current tuple to the functor.
Definition utility.hh:272
Pass the index of the current tuple to the functor as its first argument in a std::integral_constant.
Definition utility.hh:275