6#ifndef DUNE_TYPETREE_CHILDEXTRACTION_HH
7#define DUNE_TYPETREE_CHILDEXTRACTION_HH
13#include <dune/common/documentation.hh>
14#include <dune/common/indices.hh>
15#include <dune/common/typetraits.hh>
16#include <dune/common/shared_ptr.hh>
18#include <dune/common/typetree/childaccess.hh>
20#include <dune/typetree/treepath.hh>
31 template <
class Node,
class Index>
32 std::true_type checkChildIndex (Node
const& node, Index i)
34 assert(std::size_t(i) < node.degree() &&
"Child index out of range");
39 template <
class Node, std::
size_t i>
40 std::bool_constant<(i <
Node::degree())> checkChildIndex (Node
const& node, index_constant<i>)
42 static_assert(i <
Node::degree(),
"Child index out of range");
46 template<
class NodePtr>
47 auto childStorageImpl (NodePtr&& nodePtr)
49 return std::forward<NodePtr>(nodePtr);
53 template<
class NodePtr,
class I0,
class... I>
54 decltype(
auto) childStorageImpl (NodePtr&& nodePtr, I0 i0, [[maybe_unused]] I... i)
56 auto valid = checkChildIndex(*nodePtr,i0);
58 return childStorageImpl(nodePtr->childStorage(i0),i...);
64 template<
class NodePtr,
class... Indices, std::size_t... i>
65 decltype(
auto) childStorage (NodePtr&& nodePtr, [[maybe_unused]] HybridTreePath<Indices...> tp, std::index_sequence<i...>)
67 return childStorageImpl(std::forward<NodePtr>(nodePtr),treePathEntry<i>(tp)...);
74 template<
typename Node,
typename... Indices>
75 auto childStorage (Node&& node, Indices... indices)
77 static_assert(
sizeof...(Indices) > 0,
"childStorage() cannot be called with an empty list of child indices");
78 return Impl::childStorageImpl(&node,indices...);
81 template<
typename Node,
typename... Indices>
82 auto childStorage (Node&& node, HybridTreePath<Indices...> treePath)
84 static_assert(
sizeof...(Indices) > 0,
"childStorage() cannot be called with an empty TreePath");
85 return Impl::childStorage(&node, treePath, std::index_sequence_for<Indices...>{});
96 using type = std::is_integral<T>;
100 template<std::
size_t i>
101 struct _is_flat_index<index_constant<i>>
103 using type = std::true_type;
117 using is_flat_index =
typename impl::_is_flat_index<std::decay_t<T>>::type;
127 constexpr typename std::enable_if<
128 Dune::TypeTree::is_flat_index<T>::value,
131 _non_empty_tree_path (T)
137 constexpr typename std::enable_if<
138 !Dune::TypeTree::is_flat_index<T>::value,
141 _non_empty_tree_path (T t)
std::size_t degree(const Node &node)
Returns the degree of node as run time information.
Definition: nodeinterface.hh:79
constexpr std::size_t treePathSize(const HybridTreePath< T... > &)
Returns the size (number of components) of the given HybridTreePath.
Definition: treepath.hh:191