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;
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>
187 using Dune::index_constant;
188 namespace Indices = Dune::Indices;
191 template<
typename... Args>
196 namespace apply_to_tuple_policy {
212 template<
typename T,
typename F, std::size_t... i>
215 discard((f(std::get<i>(std::forward<T>(t))),0)...);
219 template<
typename T,
typename F, std::size_t... i>
220 void _apply_to_tuple(T&& t, F&& f, std::index_sequence<i...>,apply_to_tuple_policy::pass_index)
222 discard((f(index_constant<i>{},std::get<i>(std::forward<T>(t))),0)...);
235 template<
typename T,
typename F,
typename Policy>
238 const std::size_t size = std::tuple_size<typename std::decay<T>::type>::value;
242 std::make_index_sequence<size>{},
252 #endif // DUNE_TYPETREE_UTILITY_HH