Dune TypeTree (unstable)

treepath.hh
1// -*- tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=8 sw=2 sts=2:
3// SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root
4// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-GPL-2.0-only-with-PDELab-exception
5
6#ifndef DUNE_TYPETREE_TREEPATH_HH
7#define DUNE_TYPETREE_TREEPATH_HH
8
9#include <cstddef>
10#include <cassert>
11#include <iostream>
12#include <type_traits>
13
14#include <dune/common/documentation.hh>
15#include <dune/common/typetraits.hh>
16#include <dune/common/indices.hh>
17
18#include <dune/common/typetree/treepath.hh>
19
20
21namespace Dune {
22 namespace TypeTree {
23
24 // The Impl namespace collects some free standing functions helper functions
25 namespace Impl {
26
27 template<class T>
28 constexpr bool isHybridSizeT()
29 {
30 if constexpr (std::is_same_v<T, std::size_t>)
31 return true;
32 else
33 {
34 if constexpr (requires { T::value; })
35 return std::is_same_v<T, std::integral_constant<std::size_t, T::value>>;
36 else
37 return false;
38 }
39 }
40
41 template<class T>
42 constexpr auto castToHybridSizeT(T t)
43 {
44 if constexpr (Dune::IsIntegralConstant<T>::value)
45 {
46 using VT = typename T::value_type;
47 static_assert(
48 std::is_convertible_v<VT,std::size_t> &&
49 std::is_integral_v<VT> &&
50 T::value >= 0,
51 "HybridTreePath indices must be convertible to std::size_t or std::integral_constant<std::size_t,v>");
52 return std::integral_constant<std::size_t, T::value>{};
53 } else {
54 static_assert(
55 std::is_convertible_v<T,std::size_t> &&
56 std::is_integral_v<T>,
57 "HybridTreePath indices must be convertible to std::size_t or std::integral_constant<std::size_t,v>");
58 assert(t >= 0 &&
59 "HybridTreePath indices must be convertible to std::size_t or std::integral_constant<std::size_t,v>");
60 return std::size_t(t);
61 }
62 }
63
64 }
65
69
71
84 template<typename... T>
85 using HybridTreePath = Dune::HybridMultiIndex<T...>;
86
88
100 template<typename... T>
101 requires (((std::is_integral_v<T> or Dune::IsIntegralConstant<T>::value) && ...))
102 [[nodiscard]] constexpr auto hybridTreePath(const T&... t)
103 {
104 return HybridMultiIndex(t...);
105 }
106
107 namespace TreePathType {
108 enum Type { fullyStatic, dynamic };
109 }
110
114 template<typename>
116
120 template<typename,std::size_t>
122
126 template<typename,std::size_t>
128
132 template<typename>
134
138 template<typename>
140
144 template<typename, std::size_t...>
146
150 template<typename>
152
156 template<typename, typename>
158
159 template<std::size_t... i>
160 [[deprecated("This function will be removed after Dune 2.11.")]]
161 void print_tree_path(std::ostream& os)
162 {}
163
164 template<std::size_t k, std::size_t... i>
165 [[deprecated("This function will be removed after Dune 2.11.")]]
166 void print_tree_path(std::ostream& os)
167 {
168 os << k << " ";
169 print_tree_path<i...>(os);
170 }
171
173
182 template<typename... T>
183 requires (((std::is_integral_v<T> or Dune::IsIntegralConstant<T>::value) && ...))
184 [[nodiscard]] constexpr auto makeTreePath(const T... t)
185 {
186 return HybridMultiIndex(t...);
187 }
188
190 template<typename... T>
191 [[nodiscard]] constexpr std::size_t treePathSize(const HybridTreePath<T...>&)
192 {
193 return sizeof...(T);
194 }
195
197
213 template<std::size_t i, typename... T>
214 [[nodiscard]] constexpr auto treePathEntry(const HybridTreePath<T...>& tp, index_constant<i> = {})
215 {
216 return tp[index_constant<i>{}];
217 }
218
220
237 template<std::size_t i,typename... T>
238 [[deprecated("This function will be removed after Dune 2.11. Use operator[] instead.")]]
239 [[nodiscard]] constexpr std::size_t treePathIndex(const HybridTreePath<T...>& tp, index_constant<i> = {})
240 {
241 return tp[index_constant<i>{}];
242 }
243
244 template<std::size_t... i>
245 struct
246 [[deprecated("This class will be removed after Dune 2.11. Use the size() member function instead.")]]
247 TreePathSize<HybridTreePath<index_constant<i>...> >
248 : public index_constant<sizeof...(i)>
249 {};
250
251
252 template<std::size_t k, std::size_t... i>
253 struct
254 [[deprecated("This class will be removed after Dune 2.11. Use the free push_back() function instead.")]]
255 TreePathPushBack<HybridTreePath<index_constant<i>...>,k>
256 {
257 typedef HybridTreePath<index_constant<i>...,index_constant<k>> type;
258 };
259
260 template<std::size_t k, std::size_t... i>
261 struct
262 [[deprecated("This class will be removed after Dune 2.11. Use the free push_front() function instead.")]]
263 TreePathPushFront<HybridTreePath<index_constant<i>...>,k>
264 {
265 typedef HybridTreePath<index_constant<k>,index_constant<i>...> type;
266 };
267
268 template<std::size_t k>
269 struct
270 [[deprecated("This class will be removed after Dune 2.11. Use the back() member function instead.")]]
271 TreePathBack<HybridTreePath<index_constant<k>>>
272 : public index_constant<k>
273 {};
274
275 template<std::size_t j, std::size_t k, std::size_t... l>
276 struct
277 [[deprecated("This class will be removed after Dune 2.11. Use the back() member function instead.")]]
278 TreePathBack<HybridTreePath<index_constant<j>,index_constant<k>,index_constant<l>...>>
279 : public TreePathBack<HybridTreePath<index_constant<k>,index_constant<l>...>>
280 {};
281
282 template<std::size_t k, std::size_t... i>
283 struct
284 [[deprecated("This class will be removed after Dune 2.11. Use the front() member function instead.")]]
285 TreePathFront<HybridTreePath<index_constant<k>,index_constant<i>...>>
286 : public index_constant<k>
287 {};
288
289 template<std::size_t k, std::size_t... i>
290 struct
291 [[deprecated("This class will be removed after Dune 2.11. Use the free pop_back() function instead.")]]
292 TreePathPopBack<HybridTreePath<index_constant<k>>,i...>
293 {
294 typedef HybridTreePath<index_constant<i>...> type;
295 };
296
297 template<std::size_t j,
298 std::size_t k,
299 std::size_t... l,
300 std::size_t... i>
301 struct
302 [[deprecated("This class will be removed after Dune 2.11. Use the free pop_back() function instead.")]]
303 TreePathPopBack<HybridTreePath<index_constant<j>,index_constant<k>,index_constant<l>...>,i...>
304 : public TreePathPopBack<HybridTreePath<index_constant<k>,index_constant<l>...>,i...,j>
305 {};
306
307 template<std::size_t k, std::size_t... i>
308 struct
309 [[deprecated("This class will be removed after Dune 2.11. Use the free pop_front() function instead.")]]
310 TreePathPopFront<HybridTreePath<index_constant<k>,index_constant<i>...> >
311 {
312 typedef HybridTreePath<index_constant<i>...> type;
313 };
314
315 template<std::size_t... i, std::size_t... k>
316 struct
317 [[deprecated("This class will be removed after Dune 2.11. Use the free join() function instead.")]]
318 TreePathConcat<HybridTreePath<index_constant<i>...>,HybridTreePath<index_constant<k>...> >
319 {
320 typedef HybridTreePath<index_constant<i>...,index_constant<k>...> type;
321 };
322
323 template<std::size_t... i>
324 using StaticTreePath = HybridTreePath<Dune::index_constant<i>...>;
325
327
328 } // namespace TypeTree
329} //namespace Dune
330
331
332
333#endif // DUNE_TYPETREE_TREEPATH_HH
constexpr auto treePathEntry(const HybridTreePath< T... > &tp, index_constant< i >={})
Returns a copy of the i-th element of the HybridTreePath.
Definition: treepath.hh:214
constexpr std::size_t treePathSize(const HybridTreePath< T... > &)
Returns the size (number of components) of the given HybridTreePath.
Definition: treepath.hh:191
constexpr auto makeTreePath(const T... t)
helper function to construct a new HybridTreePath from the given indices.
Definition: treepath.hh:184
constexpr auto hybridTreePath(const T &... t)
Constructs a new HybridTreePath from the given indices.
Definition: treepath.hh:102
constexpr std::size_t treePathIndex(const HybridTreePath< T... > &tp, index_constant< i >={})
Returns the index value of the i-th element of the HybridTreePath.
Definition: treepath.hh:239
Dune::HybridMultiIndex< T... > HybridTreePath
A type for representing tree paths that supports both compile time and run time indices.
Definition: treepath.hh:85
Definition: treepath.hh:133
Definition: treepath.hh:157
Definition: treepath.hh:139
Definition: treepath.hh:145
Definition: treepath.hh:151
Definition: treepath.hh:121
Definition: treepath.hh:127
Definition: treepath.hh:115
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden & Uni Heidelberg  |  generated with Hugo v0.111.3 (Jan 9, 23:34, 2026)