4#ifndef DUNE_TYPETREE_UTILITY_HH
5#define DUNE_TYPETREE_UTILITY_HH
13#include <dune/common/indices.hh>
14#include <dune/typetree/nodeinterface.hh>
15#include <dune/typetree/nodetags.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)
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;
134 typedef typename Node::template Child<k>::Type
Child;
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>
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)
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>{},
std::integral_constant< std::size_t, i > index_constant
An index constant with value i.
Definition: indices.hh:28
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:236
void discard(Args &&... args)
No-op function to make calling a function on a variadic template argument pack legal C++.
Definition: utility.hh:192
Namespace with predefined compile time indices for the range [0,19].
Definition: indices.hh:49
no_pass_index default_policy
Default policy.
Definition: utility.hh:205
Dune namespace.
Definition: alignedallocator.hh:14
shared_ptr< T > stackobject_to_shared_ptr(T &t)
Create a shared_ptr for a stack-allocated object.
Definition: shared_ptr.hh:75
This file implements the class shared_ptr (a reference counting pointer), for those systems that don'...
Tag designating a leaf node.
Definition: nodetags.hh:16
Struct for obtaining some basic structural information about a TypeTree.
Definition: utility.hh:66
static const std::size_t leafCount
The number of leaf nodes in the TypeTree.
Definition: utility.hh:81
static const std::size_t depth
The depth of the TypeTree.
Definition: utility.hh:75
static const std::size_t nodeCount
The total number of nodes in the TypeTree.
Definition: utility.hh:78
Do not pass the index of the current tuple to the functor.
Definition: utility.hh:199
Pass the index of the current tuple to the functor as its first argument in a std::integral_constant.
Definition: utility.hh:202