4#ifndef DUNE_TYPETREE_CHILDEXTRACTION_HH
5#define DUNE_TYPETREE_CHILDEXTRACTION_HH
10#include <dune/common/concept.hh>
11#include <dune/common/documentation.hh>
12#include <dune/common/typetraits.hh>
13#include <dune/common/shared_ptr.hh>
32 template <
class Node,
class Index>
33 std::true_type checkChildIndex (Node
const& node, Index i)
35 assert(std::size_t(i) < node.degree() &&
"Child index out of range");
40 template <
class Node, std::
size_t i>
41 std::bool_constant<(i < Node::degree())> checkChildIndex (Node
const& node, index_constant<i>)
43 static_assert(i < Node::degree(),
"Child index out of range");
50 decltype(
auto) childImpl (Node&& node)
52 return std::forward<Node>(node);
55 template<
class NodePtr>
56 auto childStorageImpl (NodePtr&& nodePtr)
58 return std::forward<NodePtr>(nodePtr);
62 template<
class Node,
class I0,
class... I>
63 decltype(
auto) childImpl (Node&& node, I0 i0, I... i)
65 auto valid = checkChildIndex(node,i0);
67 return childImpl(node.child(i0),i...);
73 template<
class NodePtr,
class I0,
class... I>
74 decltype(
auto) childStorageImpl (NodePtr&& nodePtr, I0 i0, I... i)
76 auto valid = checkChildIndex(*nodePtr,i0);
78 return childStorageImpl(nodePtr->childStorage(i0),i...);
84 template<
class Node,
class... Indices, std::size_t... i>
85 decltype(
auto) child (Node&& node, HybridTreePath<Indices...> tp, std::index_sequence<i...>)
87 return childImpl(std::forward<Node>(node),treePathEntry<i>(tp)...);
91 template<
class NodePtr,
class... Indices, std::size_t... i>
92 decltype(
auto) childStorage (NodePtr&& nodePtr, HybridTreePath<Indices...> tp, std::index_sequence<i...>)
94 return childStorageImpl(std::forward<NodePtr>(nodePtr),treePathEntry<i>(tp)...);
124 template<
typename Node,
typename... Indices>
126 ImplementationDefined
child (Node&& node, Indices... indices)
128 decltype(
auto)
child (Node&& node, Indices... indices)
131 return Impl::childImpl(std::forward<Node>(node),indices...);
134 template<
typename Node,
typename... Indices>
141 static_assert(
sizeof...(Indices) > 0,
"childStorage() cannot be called with an empty list of child indices");
142 return Impl::childStorageImpl(&node,indices...);
169 template<
typename Node,
typename... Indices>
176 return Impl::child(std::forward<Node>(node),tp,std::index_sequence_for<Indices...>{});
179 template<
typename Node,
typename... Indices>
181 ImplementationDefined
child (Node&& node, HybridTreePath<Indices...>
treePath)
183 auto childStorage (Node&& node, HybridTreePath<Indices...> tp)
186 static_assert(
sizeof...(Indices) > 0,
"childStorage() cannot be called with an empty TreePath");
187 return Impl::childStorage(&node,tp,std::index_sequence_for<Indices...>{});
202 struct filter_void<void>
205 template<
typename Node, std::size_t... indices>
207 :
public filter_void<std::decay_t<decltype(child(std::declval<Node>(),index_constant<indices>{}...))>>
222 template<
typename Node, std::size_t... indices>
223 using Child =
typename impl::_Child<Node,indices...>::type;
230 template<
typename Node,
typename TreePath>
231 struct _ChildForTreePath
233 using type =
typename std::decay<decltype(child(std::declval<Node>(),std::declval<TreePath>()))>::type;
249 template<
typename Node,
typename TreePath>
259 struct _is_flat_index
261 using type = std::is_integral<T>;
265 template<std::
size_t i>
266 struct _is_flat_index<index_constant<i>>
268 using type = std::true_type;
292 constexpr typename std::enable_if<
296 _non_empty_tree_path (T)
302 constexpr typename std::enable_if<
306 _non_empty_tree_path (T t)
typename impl::_is_flat_index< std::decay_t< T > >::type is_flat_index
Type trait that determines whether T is a flat index in the context of child extraction.
Definition: childextraction.hh:282
ImplementationDefined childStorage(Node &&node, Indices... indices)
Definition: childextraction.hh:136
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:223
ImplementationDefined child(Node &&node, Indices... indices)
Extracts the child of a node given by a sequence of compile-time and run-time indices.
Definition: childextraction.hh:126
typename impl::_ChildForTreePath< Node, TreePath >::type ChildForTreePath
Template alias for the type of a child node given by a TreePath or a HybridTreePath type.
Definition: childextraction.hh:250
constexpr std::size_t treePathSize(const HybridTreePath< T... > &)
Returns the size (number of components) of the given HybridTreePath.
Definition: treepath.hh:196
constexpr HybridTreePath< T... > treePath(const T &... t)
Constructs a new HybridTreePath from the given indices.
Definition: treepath.hh:188
Definition: accumulate_static.hh:13
A hybrid version of TreePath that supports both compile time and run time indices.
Definition: treepath.hh:79