6#ifndef DUNE_TYPETREE_CHILDEXTRACTION_HH
7#define DUNE_TYPETREE_CHILDEXTRACTION_HH
12#include <dune/common/concept.hh>
13#include <dune/common/documentation.hh>
14#include <dune/common/typetraits.hh>
15#include <dune/common/shared_ptr.hh>
34 template <
class Node,
class Index>
35 std::true_type checkChildIndex (Node
const& node, Index i)
37 assert(std::size_t(i) < node.degree() &&
"Child index out of range");
42 template <
class Node, std::
size_t i>
43 std::bool_constant<(i < Node::degree())> checkChildIndex (Node
const& node, index_constant<i>)
45 static_assert(i < Node::degree(),
"Child index out of range");
52 decltype(
auto) childImpl (Node&& node)
54 return std::forward<Node>(node);
57 template<
class NodePtr>
58 auto childStorageImpl (NodePtr&& nodePtr)
60 return std::forward<NodePtr>(nodePtr);
64 template<
class Node,
class I0,
class... I>
65 decltype(
auto) childImpl (Node&& node, I0 i0, [[maybe_unused]] I... i)
67 auto valid = checkChildIndex(node,i0);
69 return childImpl(node.child(i0),i...);
75 template<
class NodePtr,
class I0,
class... I>
76 decltype(
auto) childStorageImpl (NodePtr&& nodePtr, I0 i0, [[maybe_unused]] I... i)
78 auto valid = checkChildIndex(*nodePtr,i0);
80 return childStorageImpl(nodePtr->childStorage(i0),i...);
86 template<
class Node,
class... Indices, std::size_t... i>
87 decltype(
auto)
child (Node&& node, [[maybe_unused]] HybridTreePath<Indices...> tp, std::index_sequence<i...>)
89 return childImpl(std::forward<Node>(node),treePathEntry<i>(tp)...);
93 template<
class NodePtr,
class... Indices, std::size_t... i>
94 decltype(
auto)
childStorage (NodePtr&& nodePtr, [[maybe_unused]] HybridTreePath<Indices...> tp, std::index_sequence<i...>)
96 return childStorageImpl(std::forward<NodePtr>(nodePtr),treePathEntry<i>(tp)...);
126 template<
typename Node,
typename... Indices>
128 ImplementationDefined
child (Node&& node, Indices... indices)
130 decltype(
auto)
child (Node&& node, Indices... indices)
133 return Impl::childImpl(std::forward<Node>(node),indices...);
136 template<
typename Node,
typename... Indices>
143 static_assert(
sizeof...(Indices) > 0,
"childStorage() cannot be called with an empty list of child indices");
144 return Impl::childStorageImpl(&node,indices...);
171 template<
typename Node,
typename... Indices>
178 return Impl::child(std::forward<Node>(node),tp,std::index_sequence_for<Indices...>{});
181 template<
typename Node,
typename... Indices>
183 ImplementationDefined
child (Node&& node, HybridTreePath<Indices...>
treePath)
185 auto childStorage (Node&& node, HybridTreePath<Indices...> tp)
188 static_assert(
sizeof...(Indices) > 0,
"childStorage() cannot be called with an empty TreePath");
189 return Impl::childStorage(&node,tp,std::index_sequence_for<Indices...>{});
204 struct filter_void<void>
207 template<
typename Node, std::size_t... indices>
209 :
public filter_void<std::decay_t<decltype(child(std::declval<Node>(),index_constant<indices>{}...))>>
224 template<
typename Node, std::size_t... indices>
225 using Child =
typename impl::_Child<Node,indices...>::type;
232 template<
typename Node,
typename TreePath>
233 struct _ChildForTreePath
235 using type =
typename std::decay<decltype(child(std::declval<Node>(),std::declval<TreePath>()))>::type;
251 template<
typename Node,
typename TreePath>
261 struct _is_flat_index
263 using type = std::is_integral<T>;
267 template<std::
size_t i>
268 struct _is_flat_index<index_constant<i>>
270 using type = std::true_type;
294 constexpr typename std::enable_if<
298 _non_empty_tree_path (T)
304 constexpr typename std::enable_if<
308 _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:284
ImplementationDefined childStorage(Node &&node, Indices... indices)
Definition childextraction.hh:138
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:225
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:128
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:252
constexpr std::size_t treePathSize(const HybridTreePath< T... > &)
Returns the size (number of components) of the given HybridTreePath.
Definition treepath.hh:334
constexpr auto treePath(const T &... t)
Constructs a new HybridTreePath from the given indices.
Definition treepath.hh:326
Definition accumulate_static.hh:16
A hybrid version of TreePath that supports both compile time and run time indices.
Definition treepath.hh:158