4 #ifndef DUNE_TYPETREE_UTILITY_HH
5 #define DUNE_TYPETREE_UTILITY_HH
7 #include <dune/common/shared_ptr.hh>
8 #include <dune/common/static_assert.hh>
9 #include <dune/common/tuples.hh>
22 shared_ptr<T> convert_arg(
const T& t)
24 return make_shared<T>(t);
28 shared_ptr<T> convert_arg(T& t)
30 return stackobject_to_shared_ptr(t);
33 template<
typename BaseType,
typename T>
34 T& assertGridViewType(T& t)
36 dune_static_assert((is_same<
typename BaseType::Traits::GridViewType,
37 typename T::Traits::GridViewType>::
value),
38 "GridViewType must be equal in all components of composite type");
43 template<
typename BaseType>
44 TypeTree::EmptyNode assertGridViewType(TypeTree::EmptyNode e)
49 #if HAVE_RVALUE_REFERENCES
55 return make_shared<T>(std::forward<T>(t));
73 template<
typename Tree,
typename Tag = StartTag>
103 template<
typename Node>
107 static const std::size_t
depth = 1;
117 template<
typename Node>
118 struct TreeInfo<Node,PowerNodeTag>
121 typedef TreeInfo<typename Node::ChildType,typename Node::ChildType::NodeTag> ChildInfo;
123 static const std::size_t
depth = 1 + ChildInfo::depth;
125 static const std::size_t
nodeCount = 1 + Node::CHILDREN * ChildInfo::nodeCount;
127 static const std::size_t
leafCount = Node::CHILDREN * ChildInfo::leafCount;
136 template<
typename Node, std::
size_t k, std::
size_t n>
137 struct generic_compositenode_children_info
140 typedef generic_compositenode_children_info<Node,k+1,n> NextChild;
144 typedef typename Child::NodeTag ChildTag;
145 typedef TreeInfo<Child,ChildTag> ChildInfo;
148 static const std::size_t maxDepth = ChildInfo::depth > NextChild::maxDepth ? ChildInfo::depth : NextChild::maxDepth;
150 static const std::size_t nodeCount = ChildInfo::nodeCount + NextChild::nodeCount;
152 static const std::size_t leafCount = ChildInfo::leafCount + NextChild::leafCount;
157 template<
typename Node, std::
size_t n>
158 struct generic_compositenode_children_info<Node,n,n>
160 static const std::size_t maxDepth = 0;
162 static const std::size_t nodeCount = 0;
164 static const std::size_t leafCount = 0;
171 template<
typename Node>
172 struct GenericCompositeNodeInfo
175 typedef generic_compositenode_children_info<Node,0,Node::CHILDREN> Children;
177 static const std::size_t depth = 1 + Children::maxDepth;
179 static const std::size_t nodeCount = 1 + Children::nodeCount;
181 static const std::size_t leafCount = Children::leafCount;
187 template<
typename Node>
188 struct TreeInfo<Node,CompositeNodeTag>
189 :
public GenericCompositeNodeInfo<Node>
194 template<
typename Node>
195 struct TreeInfo<Node,VariadicCompositeNodeTag>
196 :
public GenericCompositeNodeInfo<Node>
202 #if HAVE_VARIADIC_TEMPLATES
223 template<std::size_t... i>
224 struct index_pack {};
227 template<std::size_t n, std::size_t... i>
228 struct index_pack_builder
229 :
public index_pack_builder<n-1,n-1,i...>
233 typedef index_pack<0,1,...,n-1> type;
242 template<std::size_t... i>
243 struct index_pack_builder<0,i...>
245 typedef index_pack<i...> type;
251 template<
typename tuple>
252 struct tuple_index_pack_builder
253 :
public index_pack_builder<tuple_size<tuple>::value>
257 template<
typename tuple>
258 typename tuple_index_pack_builder<tuple>::type tuple_indices(
const tuple& t)
260 return typename tuple_index_pack_builder<tuple>::type();
268 template<std::
size_t n>
269 typename index_pack_builder<n>::type index_range()
271 return typename index_pack_builder<n>::type();
278 template<
typename... Args>
279 void discard(Args&&... args)
282 #endif // HAVE_VARIADIC_TEMPLATES
289 #endif // DUNE_TYPETREE_UTILITY_HH
const shared_ptr< EmptyNode > & emptyNodePtr()
Reference to a pointer to an empty node that is used for all empty slots.
Definition: utility.cc:12
static const std::size_t nodeCount
The total number of nodes in the TypeTree.
Definition: utility.hh:87
static const std::size_t leafCount
The number of leaf nodes in the TypeTree.
Definition: utility.hh:90
Struct for obtaining some basic structural information about a TypeTree.
Definition: utility.hh:74
static const std::size_t value
Definition: compositenode.hh:38
static const std::size_t depth
The depth of the TypeTree.
Definition: utility.hh:84
Type
Definition: treepath.hh:26
Tag designating a leaf node.
Definition: nodetags.hh:16