DUNE PDELab (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
16#include <dune/common/indices.hh>
17#include <dune/common/hybridutilities.hh>
18#include <dune/common/typelist.hh>
19
20#include <dune/typetree/hybridmultiindex.hh>
21
22
23namespace Dune {
24 namespace TypeTree {
25
26 // The Impl namespace collects some free standing functions helper functions
27 namespace Impl {
28
29 template<class T>
30 constexpr bool isHybridSizeT()
31 {
32 if constexpr (std::is_same_v<T, std::size_t>)
33 return true;
34 else
35 {
36 if constexpr (requires { T::value; })
37 return std::is_same_v<T, std::integral_constant<std::size_t, T::value>>;
38 else
39 return false;
40 }
41 }
42
43 template<class T>
44 constexpr auto castToHybridSizeT(T t)
45 {
47 {
48 using VT = typename T::value_type;
49 static_assert(
50 std::is_convertible_v<VT,std::size_t> &&
51 std::is_integral_v<VT> &&
52 T::value >= 0,
53 "HybridTreePath indices must be convertible to std::size_t or std::integral_constant<std::size_t,v>");
54 return std::integral_constant<std::size_t, T::value>{};
55 } else {
56 static_assert(
57 std::is_convertible_v<T,std::size_t> &&
58 std::is_integral_v<T>,
59 "HybridTreePath indices must be convertible to std::size_t or std::integral_constant<std::size_t,v>");
60 assert(t >= 0 &&
61 "HybridTreePath indices must be convertible to std::size_t or std::integral_constant<std::size_t,v>");
62 return std::size_t(t);
63 }
64 }
65
66 }
67
71
72 namespace TreePathType {
73 enum Type { fullyStatic, dynamic };
74 }
75
79 template<typename>
81
85 template<typename,std::size_t>
87
91 template<typename,std::size_t>
93
97 template<typename>
99
103 template<typename>
105
109 template<typename, std::size_t...>
111
115 template<typename>
117
121 template<typename, typename>
123
124 template<std::size_t... i>
125 [[deprecated("This function will be removed after Dune 2.11.")]]
126 void print_tree_path(std::ostream& os)
127 {}
128
129 template<std::size_t k, std::size_t... i>
130 [[deprecated("This function will be removed after Dune 2.11.")]]
131 void print_tree_path(std::ostream& os)
132 {
133 os << k << " ";
134 print_tree_path<i...>(os);
135 }
136
138
151 template<typename... T>
153
155
164 template<typename... T>
165 requires (((std::is_integral_v<T> or Dune::IsIntegralConstant<T>::value) && ...))
166 [[nodiscard]] constexpr auto makeTreePath(const T... t)
167 {
168 return HybridMultiIndex(t...);
169 }
170
172
182 template<typename... T>
183 requires (((std::is_integral_v<T> or Dune::IsIntegralConstant<T>::value) && ...))
184 [[nodiscard]] constexpr auto hybridTreePath(const T&... t)
185 {
186 return HybridMultiIndex(t...);
187 }
188
190
197 template<typename... T>
198 requires (((std::is_integral_v<T> or Dune::IsIntegralConstant<T>::value) && ...))
199 [[nodiscard]] constexpr auto treePath(const T&... t)
200 {
201 return HybridMultiIndex(t...);
202 }
203
204
206 template<typename... T>
207 [[nodiscard]] constexpr std::size_t treePathSize(const HybridTreePath<T...>&)
208 {
209 return sizeof...(T);
210 }
211
213
229 template<std::size_t i, typename... T>
230 [[nodiscard]] constexpr auto treePathEntry(const HybridTreePath<T...>& tp, index_constant<i> = {})
231 {
232 return tp[index_constant<i>{}];
233 }
234
236
253 template<std::size_t i,typename... T>
254 [[deprecated("This function will be removed after Dune 2.11. Use operator[] instead.")]]
255 [[nodiscard]] constexpr std::size_t treePathIndex(const HybridTreePath<T...>& tp, index_constant<i> = {})
256 {
257 return tp[index_constant<i>{}];
258 }
259
260 // Pull in the free utility function for HybridMultiIndex/HybridTreePath
261 // We cannot add forwarding functions of the same name here, since this
262 // leads to ambiguous overloads.
263 // Unfortunately doxygen ignores documentation for using statements.
264 using Dune::back;
265 using Dune::front;
266 using Dune::push_back;
267 using Dune::push_front;
270 using Dune::join;
271 using Dune::reverse;
272 using Dune::pop_front;
273 using Dune::pop_back;
274
275 inline namespace Literals {
276
278
282 template <char... digits>
283 constexpr auto operator""_tp()
284 {
285 using namespace Dune::Indices::Literals;
286 return hybridTreePath(operator""_ic<digits...>());
287 }
288
289 } // end namespace Literals
290
291
292 template<std::size_t... i>
293 struct
294 [[deprecated("This class will be removed after Dune 2.11. Use the size() member function instead.")]]
295 TreePathSize<HybridTreePath<index_constant<i>...> >
296 : public index_constant<sizeof...(i)>
297 {};
298
299
300 template<std::size_t k, std::size_t... i>
301 struct
302 [[deprecated("This class will be removed after Dune 2.11. Use the free push_back() function instead.")]]
303 TreePathPushBack<HybridTreePath<index_constant<i>...>,k>
304 {
305 typedef HybridTreePath<index_constant<i>...,index_constant<k>> type;
306 };
307
308 template<std::size_t k, std::size_t... i>
309 struct
310 [[deprecated("This class will be removed after Dune 2.11. Use the free push_front() function instead.")]]
311 TreePathPushFront<HybridTreePath<index_constant<i>...>,k>
312 {
313 typedef HybridTreePath<index_constant<k>,index_constant<i>...> type;
314 };
315
316 template<std::size_t k>
317 struct
318 [[deprecated("This class will be removed after Dune 2.11. Use the back() member function instead.")]]
319 TreePathBack<HybridTreePath<index_constant<k>>>
320 : public index_constant<k>
321 {};
322
323 template<std::size_t j, std::size_t k, std::size_t... l>
324 struct
325 [[deprecated("This class will be removed after Dune 2.11. Use the back() member function instead.")]]
326 TreePathBack<HybridTreePath<index_constant<j>,index_constant<k>,index_constant<l>...>>
327 : public TreePathBack<HybridTreePath<index_constant<k>,index_constant<l>...>>
328 {};
329
330 template<std::size_t k, std::size_t... i>
331 struct
332 [[deprecated("This class will be removed after Dune 2.11. Use the front() member function instead.")]]
333 TreePathFront<HybridTreePath<index_constant<k>,index_constant<i>...>>
334 : public index_constant<k>
335 {};
336
337 template<std::size_t k, std::size_t... i>
338 struct
339 [[deprecated("This class will be removed after Dune 2.11. Use the free pop_back() function instead.")]]
340 TreePathPopBack<HybridTreePath<index_constant<k>>,i...>
341 {
342 typedef HybridTreePath<index_constant<i>...> type;
343 };
344
345 template<std::size_t j,
346 std::size_t k,
347 std::size_t... l,
348 std::size_t... i>
349 struct
350 [[deprecated("This class will be removed after Dune 2.11. Use the free pop_back() function instead.")]]
351 TreePathPopBack<HybridTreePath<index_constant<j>,index_constant<k>,index_constant<l>...>,i...>
352 : public TreePathPopBack<HybridTreePath<index_constant<k>,index_constant<l>...>,i...,j>
353 {};
354
355 template<std::size_t k, std::size_t... i>
356 struct
357 [[deprecated("This class will be removed after Dune 2.11. Use the free pop_front() function instead.")]]
358 TreePathPopFront<HybridTreePath<index_constant<k>,index_constant<i>...> >
359 {
360 typedef HybridTreePath<index_constant<i>...> type;
361 };
362
363 template<std::size_t... i, std::size_t... k>
364 struct
365 [[deprecated("This class will be removed after Dune 2.11. Use the free join() function instead.")]]
366 TreePathConcat<HybridTreePath<index_constant<i>...>,HybridTreePath<index_constant<k>...> >
367 {
368 typedef HybridTreePath<index_constant<i>...,index_constant<k>...> type;
369 };
370
371 template<std::size_t... i>
372 using StaticTreePath = HybridTreePath<Dune::index_constant<i>...>;
373
375
376 } // namespace TypeTree
377} //namespace Dune
378
379
380
381#endif // DUNE_TYPETREE_TREEPATH_HH
A hybrid multi-index class that supports both compile time and run time indices.
Definition: hybridmultiindex.hh:81
Documentation related stuff.
Traits for type conversions and type information.
std::integral_constant< std::size_t, i > index_constant
An index constant with value i.
Definition: indices.hh:29
constexpr auto treePathEntry(const HybridTreePath< T... > &tp, index_constant< i >={})
Returns a copy of the i-th element of the HybridTreePath.
Definition: treepath.hh:230
constexpr std::size_t treePathSize(const HybridTreePath< T... > &)
Returns the size (number of components) of the given HybridTreePath.
Definition: treepath.hh:207
constexpr auto makeTreePath(const T... t)
helper function to construct a new HybridTreePath from the given indices.
Definition: treepath.hh:166
constexpr auto hybridTreePath(const T &... t)
Constructs a new HybridTreePath from the given indices.
Definition: treepath.hh:184
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:255
constexpr auto treePath(const T &... t)
Constructs a new HybridTreePath from the given indices.
Definition: treepath.hh:199
Dune namespace.
Definition: alignedallocator.hh:13
constexpr auto join(const HybridMultiIndex< Head... > &head, const Other &... tail)
Join two hybrid multi-indices into one.
Definition: hybridmultiindex.hh:355
constexpr std::integer_sequence< T, II..., T(IN)> push_back(std::integer_sequence< T, II... >, std::integral_constant< T, IN >={})
Append an index IN to the back of the sequence.
Definition: integersequence.hh:69
constexpr std::integer_sequence< T, T(I0), II... > push_front(std::integer_sequence< T, II... >, std::integral_constant< T, I0 >={})
Append an index I0 to the front of the sequence.
Definition: integersequence.hh:64
constexpr auto reverse(const HybridMultiIndex< T... > &tp)
Reverses the order of the elements in the multi-index.
Definition: hybridmultiindex.hh:361
constexpr auto pop_back(const HybridMultiIndex< T... > &tp)
Removes last index on a HybridMultiIndex.
Definition: hybridmultiindex.hh:387
constexpr auto pop_front(const HybridMultiIndex< T... > &tp)
Removes first index on a HybridMultiIndex.
Definition: hybridmultiindex.hh:374
constexpr auto accumulate_back(const HybridMultiIndex< T... > &tp, I i)
Hybrid utility that accumulates to the back of a multi-index.
Definition: hybridmultiindex.hh:328
constexpr std::integral_constant< T, I0 > front(std::integer_sequence< T, I0, II... >)
Return the first entry of the sequence.
Definition: integersequence.hh:39
constexpr auto accumulate_front(const HybridMultiIndex< T... > &tp, I i)
Hybrid utility that accumulates to the front of a multi-index.
Definition: hybridmultiindex.hh:348
constexpr auto back(std::integer_sequence< T, II... > seq)
Return the last entry of the sequence.
Definition: integersequence.hh:44
Check if T is an std::integral_constant<I, i>
Definition: typetraits.hh:384
Definition: treepath.hh:98
Definition: treepath.hh:122
Definition: treepath.hh:104
Definition: treepath.hh:110
Definition: treepath.hh:116
Definition: treepath.hh:86
Definition: treepath.hh:92
Definition: treepath.hh:80
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden & Uni Heidelberg  |  generated with Hugo v0.111.3 (Sep 3, 22:42, 2025)