4 #ifndef DUNE_TYPETREE_UTILITY_HH
5 #define DUNE_TYPETREE_UTILITY_HH
11 #include <dune/common/shared_ptr.hh>
12 #include <dune/common/std/utility.hh>
25 std::shared_ptr<T> convert_arg(
const T& t)
27 return std::make_shared<T>(t);
31 std::shared_ptr<T> convert_arg(T& t)
33 return stackobject_to_shared_ptr(t);
36 template<
typename BaseType,
typename T>
37 T& assertGridViewType(T& t)
39 static_assert((std::is_same<
typename BaseType::Traits::GridViewType,
40 typename T::Traits::GridViewType>::value),
41 "GridViewType must be equal in all components of composite type");
47 typename std::enable_if<!std::is_lvalue_reference<T>::value,std::shared_ptr<T> >::type convert_arg(T&& t)
49 return std::make_shared<T>(std::forward<T>(t));
62 template<
typename Tree,
typename Tag = StartTag>
92 template<
typename Node>
96 static const std::size_t
depth = 1;
106 template<
typename Node>
107 struct TreeInfo<Node,PowerNodeTag>
110 typedef TreeInfo<typename Node::ChildType,typename Node::ChildType::NodeTag> ChildInfo;
112 static const std::size_t
depth = 1 + ChildInfo::depth;
114 static const std::size_t
nodeCount = 1 + Node::CHILDREN * ChildInfo::nodeCount;
116 static const std::size_t
leafCount = Node::CHILDREN * ChildInfo::leafCount;
125 template<
typename Node, std::
size_t k, std::
size_t n>
126 struct generic_compositenode_children_info
129 typedef generic_compositenode_children_info<Node,k+1,n> NextChild;
133 typedef typename Child::NodeTag ChildTag;
134 typedef TreeInfo<Child,ChildTag> ChildInfo;
137 static const std::size_t maxDepth = ChildInfo::depth > NextChild::maxDepth ? ChildInfo::depth : NextChild::maxDepth;
139 static const std::size_t nodeCount = ChildInfo::nodeCount + NextChild::nodeCount;
141 static const std::size_t leafCount = ChildInfo::leafCount + NextChild::leafCount;
146 template<
typename Node, std::
size_t n>
147 struct generic_compositenode_children_info<Node,n,n>
149 static const std::size_t maxDepth = 0;
151 static const std::size_t nodeCount = 0;
153 static const std::size_t leafCount = 0;
160 template<
typename Node>
161 struct GenericCompositeNodeInfo
164 typedef generic_compositenode_children_info<Node,0,Node::CHILDREN> Children;
166 static const std::size_t depth = 1 + Children::maxDepth;
168 static const std::size_t nodeCount = 1 + Children::nodeCount;
170 static const std::size_t leafCount = Children::leafCount;
176 template<
typename Node>
177 struct TreeInfo<Node,CompositeNodeTag>
178 :
public GenericCompositeNodeInfo<Node>
204 template<std::size_t... i>
208 template<std::size_t n, std::size_t... i>
223 template<std::size_t... i>
232 template<
typename tuple>
238 template<
typename tuple>
249 template<std::
size_t n>
263 using Dune::Std::integer_sequence;
266 template<std::size_t... indices>
270 template<
typename T, T n>
274 template<std::
size_t n>
287 template<
typename... T>
288 struct _get_pack_length
289 :
public std::integral_constant<std::size_t,sizeof...(T)>
297 template<
typename... T>
311 template<std::
size_t i>
402 template<
typename... Args>
407 namespace apply_to_tuple_policy {
423 template<
typename T,
typename F, std::size_t... i>
426 discard((f(std::get<i>(std::forward<T>(t))),0)...);
430 template<
typename T,
typename F, std::size_t... i>
431 void _apply_to_tuple(T&& t, F&& f, Std::index_sequence<i...>,apply_to_tuple_policy::pass_index)
433 discard((f(index_constant<i>{},std::get<i>(std::forward<T>(t))),0)...);
446 template<
typename T,
typename F,
typename Policy>
449 const std::size_t size = std::tuple_size<typename std::decay<T>::type>::value;
463 #endif // DUNE_TYPETREE_UTILITY_HH
constexpr index_constant< 7 > _7
Compile time index with value 7.
Definition: utility.hh:356
constexpr index_constant< 4 > _4
Compile time index with value 4.
Definition: utility.hh:347
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:250
TMP to build an index_pack for all elements in the tuple.
Definition: utility.hh:233
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:447
static const std::size_t leafCount
The number of leaf nodes in the TypeTree.
Definition: utility.hh:79
constexpr index_constant< 10 > _10
Compile time index with value 10.
Definition: utility.hh:365
tuple_index_pack_builder< tuple >::type tuple_indices(const tuple &t)
Generate an index_pack for the tuple t.
Definition: utility.hh:239
constexpr index_constant< 1 > _1
Compile time index with value 1.
Definition: utility.hh:338
decltype(Dune::Std::make_integer_sequence< T, n >()) make_integer_sequence
Create an integer_sequence [0,n-1] with entries of type T.
Definition: utility.hh:271
Definition: accumulate_static.hh:12
constexpr index_constant< 13 > _13
Compile time index with value 13.
Definition: utility.hh:374
constexpr index_constant< 6 > _6
Compile time index with value 6.
Definition: utility.hh:353
Do not pass the index of the current tuple to the functor.
Definition: utility.hh:410
Tag designating a leaf node.
Definition: nodetags.hh:16
constexpr index_constant< 5 > _5
Compile time index with value 5.
Definition: utility.hh:350
Pass the index of the current tuple to the functor as its first argument in a std::integral_constant...
Definition: utility.hh:413
make_index_sequence< impl::_get_pack_length< T...>{}> index_sequence_for
Create an index_sequence for the pack T..., i.e. [0,sizeof...(T)].
Definition: utility.hh:298
static const std::size_t nodeCount
The total number of nodes in the TypeTree.
Definition: utility.hh:76
std::integral_constant< std::size_t, i > index_constant
An index constant with value i.
Definition: utility.hh:312
constexpr index_constant< 15 > _15
Compile time index with value 15.
Definition: utility.hh:380
constexpr index_constant< 17 > _17
Compile time index with value 17.
Definition: utility.hh:386
constexpr index_constant< 18 > _18
Compile time index with value 18.
Definition: utility.hh:389
constexpr index_constant< 12 > _12
Compile time index with value 12.
Definition: utility.hh:371
constexpr index_constant< 3 > _3
Compile time index with value 3.
Definition: utility.hh:344
constexpr index_constant< 19 > _19
Compile time index with value 19.
Definition: utility.hh:392
integer_sequence< std::size_t, indices...> index_sequence
A sequence of indices, with each entry a std::size_t.
Definition: utility.hh:267
TMP to build an index_pack containing the sequence 0,...,n-1.
Definition: utility.hh:209
void discard(Args &&...args)
No-op function to make calling a function on a variadic template argument pack legal C++...
Definition: utility.hh:403
constexpr index_constant< 8 > _8
Compile time index with value 8.
Definition: utility.hh:359
constexpr index_constant< 9 > _9
Compile time index with value 9.
Definition: utility.hh:362
constexpr index_constant< 0 > _0
Compile time index with value 0.
Definition: utility.hh:335
constexpr index_constant< 14 > _14
Compile time index with value 14.
Definition: utility.hh:377
constexpr index_constant< 2 > _2
Compile time index with value 2.
Definition: utility.hh:341
Type
Definition: treepath.hh:26
no_pass_index default_policy
Default policy.
Definition: utility.hh:416
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:568
constexpr index_constant< 16 > _16
Compile time index with value 16.
Definition: utility.hh:383
static const std::size_t depth
The depth of the TypeTree.
Definition: utility.hh:73
index_pack< 0, 1,..., n-1 > type
Result.
Definition: utility.hh:215
make_integer_sequence< std::size_t, n > make_index_sequence
Create an index_sequence [0,n-1].
Definition: utility.hh:275
Struct for obtaining some basic structural information about a TypeTree.
Definition: utility.hh:63
Simple holder class for a template argument pack of indices.
Definition: utility.hh:205
constexpr index_constant< 11 > _11
Compile time index with value 11.
Definition: utility.hh:368