4 #ifndef DUNE_TYPETREE_CHILDEXTRACTION_HH
5 #define DUNE_TYPETREE_CHILDEXTRACTION_HH
7 #include <dune/common/documentation.hh>
8 #include <dune/common/typetraits.hh>
9 #include <dune/common/shared_ptr.hh>
28 template<
typename Node,
typename TreePath>
56 template<
typename Node>
98 template<
typename Node,
typename TreePath>
130 template<
typename Node,
typename TreePath>
140 template<
typename Node,
typename TreePath>
143 typename extract_child_type<Node,TreePath>::type&
151 template<
typename Node,
typename TreePath>
153 TypeTree::TreePathSize<TreePath>::value == 1,
154 typename Node::template Child<TypeTree::TreePathFront<TreePath>::value>
::Type&
158 return node.template child<TypeTree::TreePathFront<TreePath>::value>();
161 template<
typename Node,
typename TreePath>
163 TypeTree::TreePathSize<TreePath>::value == 0,
175 template<
typename Node,
typename TreePath>
177 (TypeTree::TreePathSize<TreePath>::value > 1),
178 const typename extract_child_type<Node,TreePath>::type&
183 typename TypeTree::TreePathPopFront<TreePath>::type());
186 template<
typename Node,
typename TreePath>
188 TypeTree::TreePathSize<TreePath>::value == 1,
189 const typename Node::template Child<TypeTree::TreePathFront<TreePath>::value>
::Type&
193 return node.template child<TypeTree::TreePathFront<TreePath>::value>();
196 template<
typename Node,
typename TreePath>
198 TypeTree::TreePathSize<TreePath>::value == 0,
238 template<
typename Node,
typename TreePath>
267 template<
typename Node,
typename TreePath>
277 template<
typename Node,
typename TreePath>
279 (TypeTree::TreePathSize<TreePath>::value > 1),
280 typename extract_child_type<Node,TreePath>::storage_type
288 template<
typename Node,
typename TreePath>
290 TypeTree::TreePathSize<TreePath>::value == 1,
291 typename Node::template Child<TypeTree::TreePathFront<TreePath>::value>::Storage&
295 return node.template childStorage<TypeTree::TreePathFront<TreePath>::value>();
298 template<
typename Node,
typename TreePath>
300 TypeTree::TreePathSize<TreePath>::value == 0
304 static_assert((Dune::AlwaysFalse<Node>::value),
305 "extract_child_storage only works for real children, not the node itself.");
312 template<
typename Node,
typename TreePath>
314 (TypeTree::TreePathSize<TreePath>::value > 1),
315 typename extract_child_type<Node,TreePath>::const_storage_type
320 typename TypeTree::TreePathPopFront<TreePath>::type());
323 template<
typename Node,
typename TreePath>
325 TypeTree::TreePathSize<TreePath>::value == 1,
326 typename Node::template Child<TypeTree::TreePathFront<TreePath>::value>::ConstStorage
330 return node.template childStorage<TypeTree::TreePathFront<TreePath>::value>();
333 template<
typename Node,
typename TreePath>
335 TypeTree::TreePathSize<TreePath>::value == 0
339 static_assert((Dune::AlwaysFalse<Node>::value),
340 "extract_child_storage only works for real children, not the node itself.");
350 template<
typename Node>
351 auto child(Node&& node) -> decltype(std::forward<Node>(node))
353 return std::forward<Node>(node);
362 template<
typename Node,
typename _ = decltype(std::declval<Node>().
template child<0>())>
363 static constexpr
auto _has_template_child_method(Node*) -> std::true_type;
365 template<
typename Node>
366 static constexpr
auto _has_template_child_method(
void*) -> std::false_type;
375 template<
typename Node>
376 struct _lazy_static_decltype
378 template<
typename I,
typename... J>
381 using type = decltype(
child(std::declval<Node>().
template child<I::value>(),std::declval<J>()...));
389 template<
typename Node, std::size_t i,
typename... J>
390 auto child(Node&& node, index_constant<i>, J... j) ->
391 typename std::enable_if<
392 decltype(_has_template_child_method(std::declval<
typename std::remove_reference<Node>::type*>()))::value &&
393 (i <
std::decay<Node>::type::CHILDREN),
394 _lazy_static_decltype<
395 typename
std::remove_reference<Node>::type
399 return child(std::forward<Node>(node).
template child<i>(),j...);
408 template<
typename Node>
409 struct _lazy_dynamic_decltype
411 template<
typename... J>
414 using type = decltype(
child(std::declval<Node>().
child(0),std::declval<J>()...));
421 template<
typename Node,
typename... J>
422 auto child(Node&& node, std::size_t i, J... j) ->
423 typename std::enable_if<
425 typename std::remove_reference<Node>::type::NodeTag,
428 _lazy_dynamic_decltype<
429 typename std::remove_reference<Node>::type
431 >::type::template evaluate<J...>::type
433 return child(std::forward<Node>(node).
template child(i),j...);
436 template<
typename Node,
typename... Indices, std::size_t... i>
437 auto child(Node&& node, HybridTreePath<Indices...> tp, Std::index_sequence<i...>) -> decltype(
child(std::forward<Node>(node),treePathEntry<i>(tp)...))
439 return child(std::forward<Node>(node),treePathEntry<i>(tp)...);
470 template<
typename Node,
typename... Indices>
472 ImplementationDefined
child(Node&& node, Indices... indices)
474 auto child(Node&& node, Indices... indices) -> decltype(
impl::child(std::forward<Node>(node),indices...))
477 return impl::child(std::forward<Node>(node),indices...);
500 template<
typename Node, std::size_t... Indices>
535 template<
typename Node,
typename... Indices>
549 template<
typename Node, std::size_t... indices>
552 using type =
typename std::decay<decltype(child(std::declval<Node>(),index_constant<indices>{}...))>::type;
567 template<
typename Node, std::size_t... indices>
568 using Child =
typename impl::_Child<Node,indices...>::type;
575 template<
typename Node,
typename TreePath>
576 struct _ChildForTreePath
578 using type =
typename std::decay<decltype(child(std::declval<Node>(),std::declval<TreePath>()))>::type;
594 template<
typename Node,
typename TreePath>
604 struct _is_flat_index
606 using type = std::is_integral<T>;
610 template<std::
size_t i>
611 struct _is_flat_index<index_constant<i>>
613 using type = std::true_type;
627 using is_flat_index =
typename impl::_is_flat_index<typename std::decay<T>::type>::type;
635 template<
typename Node>
636 struct _lazy_member_child_decltype
638 template<
typename... Indices>
649 constexpr
typename std::enable_if<
653 _non_empty_tree_path(T)
659 constexpr
typename std::enable_if<
663 _non_empty_tree_path(T t)
677 #endif // DUNE_TYPETREE_CHILDEXTRACTION_HH
extract_child_type< typename Node::template Child< TypeTree::TreePathFront< TreePath >::value >::Type, typename TypeTree::TreePathPopFront< TreePath >::type >::type type
The type of the child.
Definition: childextraction.hh:36
ImplementationDefined & extract_child(Node &node, Treepath tp)
Extract the child of a node located at tp (non-const version).
Definition: childextraction.hh:99
Definition: treepath.hh:94
Definition: treepath.hh:119
Definition: accumulate_static.hh:12
Definition: treepath.hh:42
extract_child_type< typename Node::template Child< TypeTree::TreePathFront< TreePath >::value >::Type, typename TypeTree::TreePathPopFront< TreePath >::type >::const_storage_type const_storage_type
The const storage type of the child.
Definition: childextraction.hh:48
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
constexpr std::size_t treePathSize(const TreePath< i...> &)
Returns the size (number of components) of the given TreePath.
Definition: treepath.hh:51
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:472
extract_child_type< typename Node::template Child< TypeTree::TreePathFront< TreePath >::value >::Type, typename TypeTree::TreePathPopFront< TreePath >::type >::storage_type storage_type
The storage type of the child.
Definition: childextraction.hh:42
std::integral_constant< std::size_t, i > index_constant
An index constant with value i.
Definition: utility.hh:312
typename impl::_is_flat_index< typename std::decay< T >::type >::type is_flat_index
Type trait that determines whether T is a flat index in the context of child extraction.
Definition: childextraction.hh:627
A hybrid version of TreePath that supports both compile time and run time indices.
Definition: treepath.hh:322
Type
Definition: treepath.hh:26
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
ImplementationDefined child(Node &&node, HybridTreePath< Indices...> treePath)
Extracts the child of a node given by a HybridTreePath object.
Definition: childextraction.hh:537
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:595
Extract the type of the child of Node at position TreePath.
Definition: childextraction.hh:29
ImplementationDefined extract_child_storage(Node &node, Treepath tp)
Definition: childextraction.hh:239
Definition: treepath.hh:30