4 #ifndef DUNE_TYPETREE_UTILITY_HH
5 #define DUNE_TYPETREE_UTILITY_HH
7 #include <dune/common/shared_ptr.hh>
8 #include <dune/common/tuples.hh>
21 shared_ptr<T> convert_arg(
const T& t)
23 return make_shared<T>(t);
27 shared_ptr<T> convert_arg(T& t)
29 return stackobject_to_shared_ptr(t);
32 template<
typename BaseType,
typename T>
33 T& assertGridViewType(T& t)
35 static_assert((is_same<
typename BaseType::Traits::GridViewType,
36 typename T::Traits::GridViewType>::value),
37 "GridViewType must be equal in all components of composite type");
43 typename enable_if<!std::is_lvalue_reference<T>::value,shared_ptr<T> >::type convert_arg(T&& t)
45 return make_shared<T>(std::forward<T>(t));
58 template<
typename Tree,
typename Tag = StartTag>
88 template<
typename Node>
92 static const std::size_t
depth = 1;
102 template<
typename Node>
103 struct TreeInfo<Node,PowerNodeTag>
106 typedef TreeInfo<typename Node::ChildType,typename Node::ChildType::NodeTag> ChildInfo;
108 static const std::size_t
depth = 1 + ChildInfo::depth;
110 static const std::size_t
nodeCount = 1 + Node::CHILDREN * ChildInfo::nodeCount;
112 static const std::size_t
leafCount = Node::CHILDREN * ChildInfo::leafCount;
121 template<
typename Node, std::
size_t k, std::
size_t n>
122 struct generic_compositenode_children_info
125 typedef generic_compositenode_children_info<Node,k+1,n> NextChild;
129 typedef typename Child::NodeTag ChildTag;
130 typedef TreeInfo<Child,ChildTag> ChildInfo;
133 static const std::size_t maxDepth = ChildInfo::depth > NextChild::maxDepth ? ChildInfo::depth : NextChild::maxDepth;
135 static const std::size_t nodeCount = ChildInfo::nodeCount + NextChild::nodeCount;
137 static const std::size_t leafCount = ChildInfo::leafCount + NextChild::leafCount;
142 template<
typename Node, std::
size_t n>
143 struct generic_compositenode_children_info<Node,n,n>
145 static const std::size_t maxDepth = 0;
147 static const std::size_t nodeCount = 0;
149 static const std::size_t leafCount = 0;
156 template<
typename Node>
157 struct GenericCompositeNodeInfo
160 typedef generic_compositenode_children_info<Node,0,Node::CHILDREN> Children;
162 static const std::size_t depth = 1 + Children::maxDepth;
164 static const std::size_t nodeCount = 1 + Children::nodeCount;
166 static const std::size_t leafCount = Children::leafCount;
172 template<
typename Node>
173 struct TreeInfo<Node,CompositeNodeTag>
174 :
public GenericCompositeNodeInfo<Node>
200 template<std::size_t... i>
204 template<std::size_t n, std::size_t... i>
219 template<std::size_t... i>
228 template<
typename tuple>
234 template<
typename tuple>
245 template<std::
size_t n>
255 template<
typename... Args>
260 namespace apply_to_tuple_policy {
276 template<
typename T,
typename F, std::size_t... i>
279 discard((f(std::get<i>(std::forward<T>(t))),0)...);
283 template<
typename T,
typename F, std::size_t... i>
284 void _apply_to_tuple(T&& t, F&& f, index_pack<i...> indices,apply_to_tuple_policy::pass_index)
286 discard((f(std::integral_constant<std::size_t,i>(),std::get<i>(std::forward<T>(t))),0)...);
299 template<
typename T,
typename F,
typename Policy>
315 #endif // DUNE_TYPETREE_UTILITY_HH
TMP to build an index_pack for all elements in the tuple.
Definition: utility.hh:229
Pass the index of the current tuple to the functor as its first argument in a std::integral_constant...
Definition: utility.hh:266
tuple_index_pack_builder< tuple >::type tuple_indices(const tuple &t)
Generate an index_pack for the tuple t.
Definition: utility.hh:235
index_pack< 0, 1,..., n-1 > type
Result.
Definition: utility.hh:211
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:300
Simple holder class for a template argument pack of indices.
Definition: utility.hh:201
Definition: accumulate_static.hh:12
static const std::size_t leafCount
The number of leaf nodes in the TypeTree.
Definition: utility.hh:75
void discard(Args &&...args)
No-op function to make calling a function on a variadic template argument pack legal C++...
Definition: utility.hh:256
Struct for obtaining some basic structural information about a TypeTree.
Definition: utility.hh:59
static const std::size_t nodeCount
The total number of nodes in the TypeTree.
Definition: utility.hh:72
Type
Definition: treepath.hh:25
static const std::size_t depth
The depth of the TypeTree.
Definition: utility.hh:69
index_pack_builder< n >::type index_range()
Generate an index_pack with the values {0, 1, ..., n-1}.
Definition: utility.hh:246
no_pass_index default_policy
Default policy.
Definition: utility.hh:269
Do not pass the index of the current tuple to the functor.
Definition: utility.hh:263
Tag designating a leaf node.
Definition: nodetags.hh:16
TMP to build an index_pack containing the sequence 0,...,n-1.
Definition: utility.hh:205