dune-common  2.11
nodeconcepts.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 // SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root
4 // SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception OR LGPL-3.0-or-later
5 
6 #ifndef DUNE_COMMON_TYPETREE_NODECONCEPTS_HH
7 #define DUNE_COMMON_TYPETREE_NODECONCEPTS_HH
8 
10 #include <dune/common/indices.hh>
11 
12 #include <concepts>
13 #include <type_traits>
14 #include <utility>
15 
16 
18 
19  namespace Impl {
20 
21  template<class Node>
22  concept HasConstExprDegree = requires(Node node)
23  {
24  std::bool_constant<(std::remove_cvref_t<Node>::degree(), true)>();
25  };
26 
27  template<class Node>
28  concept HasPositiveDegree = ( std::remove_cvref_t<Node>::degree() > 0);
29 
30  }
31 
33  template<class Node>
34  concept TreeNode = requires(Node node)
35  {
36  { std::as_const(node).degree() } -> std::convertible_to<std::size_t>;
37  };
38 
40  template<class Node>
41  concept StaticDegreeInnerTreeNode = TreeNode<Node> && requires(Node node)
42  {
43  std::remove_cvref_t<Node>::degree();
45  requires Impl::HasConstExprDegree<Node> and Impl::HasPositiveDegree<Node>;
46  node.child(index_constant<0>());
47  node.child(index_constant<(std::remove_cvref_t<Node>::degree()-1)>());
48  };
49 
51  template<class Node>
52  concept UniformInnerTreeNode = TreeNode<Node> && requires(Node node, std::size_t index)
53  {
54  node.child(index);
55  };
56 
58  template<class Node>
59  concept InnerTreeNode = StaticDegreeInnerTreeNode<Node> || UniformInnerTreeNode<Node>;
60 
62  template<class Node>
63  concept LeafTreeNode = TreeNode<Node> && not InnerTreeNode<Node>;
64 
65 } // namespace Dune::TypeTree::Concept
66 
67 #endif // DUNE_COMMON_TYPETREE_NODECONCEPTS_HH
std::integral_constant< std::size_t, i > index_constant
An index constant with value i.
Definition: indices.hh:29
requires(((std::is_integral_v< T > or Dune::IsIntegralConstant< T >::value) &&...)) const expr auto treePath(const T &... t)
Constructs a new TreePath from the given indices.
Definition: treepath.hh:54
concept UniformInnerTreeNode
Model of an inner node of a typetree with uniform nodes accessible via runtime index.
Definition: nodeconcepts.hh:52
concept TreeNode
Model of a node of a typetree.
Definition: nodeconcepts.hh:34
concept InnerTreeNode
Model of an inner tree node of a typetree (either static degree or uniform)
Definition: nodeconcepts.hh:59
Traits for type conversions and type information.
Definition: nodeconcepts.hh:17
concept LeafTreeNode
Model of a leaf tree node of a typetree.
Definition: nodeconcepts.hh:63
Check if T is an integral constant or any type derived from std::integral_constant.
Definition: typetraits.hh:409
concept StaticDegreeInnerTreeNode
Model of an inner node of a typetree with compile time known degree and child access via index_consta...
Definition: nodeconcepts.hh:41