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>
114 static const std::size_t
depth = 1 + ChildInfo::depth;
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;
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;
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>
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>{},
325 #endif // DUNE_TYPETREE_UTILITY_HH no_pass_index default_policy
Default policy.
Definition: utility.hh:278
static const std::size_t depth
The depth of the TypeTree.
Definition: utility.hh:75
Do not pass the index of the current tuple to the functor.
Definition: utility.hh:272
Simple holder class for a template argument pack of indices.
Definition: utility.hh:207
index_pack< 0, 1,..., n-1 > type
Result.
Definition: utility.hh:217
typename impl::_Child< Node, indices... >::type Child
Template alias for the type of a child node given by a list of child indices.
Definition: childextraction.hh:307
TMP to build an index_pack for all elements in the tuple.
Definition: utility.hh:235
Definition: accumulate_static.hh:13
static const std::size_t nodeCount
The total number of nodes in the TypeTree.
Definition: utility.hh:78
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
static const std::size_t leafCount
The number of leaf nodes in the TypeTree.
Definition: utility.hh:81
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
Struct for obtaining some basic structural information about a TypeTree.
Definition: utility.hh:65
std::integral_constant< std::size_t, degree(static_cast< std::decay_t< Node > * >(nullptr), NodeTag< std::decay_t< Node > >()) > StaticDegree
Returns the statically known degree of the given Node type as a std::integral_constant.
Definition: nodeinterface.hh:105
Pass the index of the current tuple to the functor as its first argument in a std::integral_constant...
Definition: utility.hh:275
Tag designating a leaf node.
Definition: nodetags.hh:16
TMP to build an index_pack containing the sequence 0,...,n-1.
Definition: utility.hh:211
typename std::decay_t< Node >::NodeTag NodeTag
Returns the node tag of the given Node.
Definition: nodeinterface.hh:62
void discard(Args &&... args)
No-op function to make calling a function on a variadic template argument pack legal C++...
Definition: utility.hh:265
tuple_index_pack_builder< tuple >::type tuple_indices(const tuple &t)
Generate an index_pack for the tuple t.
Definition: utility.hh:241