4 #ifndef DUNE_TYPETREE_TREEPATH_HH
5 #define DUNE_TYPETREE_TREEPATH_HH
10 #include <dune/common/documentation.hh>
11 #include <dune/common/typetraits.hh>
12 #include <dune/common/indices.hh>
13 #include <dune/common/hybridutilities.hh>
22 template<
typename... T>
29 namespace TreePathType {
36 template<
typename,std::
size_t>
39 template<
typename,std::
size_t>
48 template<
typename, std::size_t...>
54 template<
typename,
typename>
57 template<std::size_t... i>
61 template<std::size_t k, std::size_t... i>
77 template<
typename... T>
99 template<
typename... U,
typename std::enable_if<(
sizeof...(T) > 0 &&
sizeof...(U) ==
sizeof...(T)),
bool>::type =
true>
111 constexpr
static std::size_t
size()
117 template<std::
size_t i>
120 return std::get<i>(_data);
126 std::size_t entry = 0;
127 Dune::Hybrid::forEach(
enumerate(), [&] (
auto i) {
135 template<std::
size_t i>
136 constexpr
auto element(Dune::index_constant<i> pos = {})
const
138 return std::get<i>(_data);
142 constexpr std::size_t
element(std::size_t pos)
const
144 std::size_t entry = 0;
145 Dune::Hybrid::forEach(
enumerate(), [&] (
auto i) {
155 return std::get<
sizeof...(T)-1>(_data);
163 using Data = std::tuple<T...>;
176 template<
typename... T>
187 template<
typename... T>
195 template<
typename... T>
218 template<std::size_t i,
typename... T>
220 ->
typename std::decay<decltype(std::get<i>(tp._data))>::type
222 return std::get<i>(tp._data);
241 template<std::size_t i,
typename... T>
244 return std::get<i>(tp._data);
253 template<
typename... T,
typename std::enable_if<(
sizeof...(T) > 0),
bool>::type =
true>
266 template<
typename... T>
268 -> decltype(treePathEntry<0>(tp))
270 return treePathEntry<0>(tp);
277 template<
typename... T>
280 return HybridTreePath<T...,std::size_t>(std::tuple_cat(tp._data,std::make_tuple(i)));
298 template<std::size_t i,
typename... T>
301 return HybridTreePath<T...,index_constant<i> >(std::tuple_cat(tp._data,std::make_tuple(i_)));
308 template<
typename... T>
311 return HybridTreePath<std::size_t,T...>(std::tuple_cat(std::make_tuple(element),tp._data));
329 template<std::size_t i,
typename... T>
332 return HybridTreePath<index_constant<i>,T...>(std::tuple_cat(std::make_tuple(_i),tp._data));
336 template<std::size_t... i>
338 :
public index_constant<sizeof...(i)>
342 template<std::size_t k, std::size_t... i>
348 template<std::size_t k, std::size_t... i>
354 template<std::
size_t k>
356 :
public index_constant<k>
359 template<std::size_t j, std::size_t k, std::size_t... l>
361 :
public TreePathBack<HybridTreePath<index_constant<k>,index_constant<l>...>>
364 template<std::size_t k, std::size_t... i>
366 :
public index_constant<k>
369 template<std::size_t k, std::size_t... i>
375 template<std::size_t j,
380 :
public TreePathPopBack<HybridTreePath<index_constant<k>,index_constant<l>...>,i...,j>
383 template<std::size_t k, std::size_t... i>
389 template<std::size_t... i, std::size_t... k>
400 template<std::size_t i,
typename... T>
401 typename std::enable_if<
408 template<std::size_t i,
typename... T>
409 typename std::enable_if<
412 print_hybrid_tree_path(std::ostream& os,
const HybridTreePath<T...>& tp, index_constant<i> _i)
415 print_hybrid_tree_path(os,tp,index_constant<i+1>{});
423 template<
typename... T>
426 os <<
"HybridTreePath< ";
427 impl::print_hybrid_tree_path(os, tp, index_constant<0>{});
432 template<std::size_t... i>
435 template<std::size_t... i>
constexpr auto back(const HybridTreePath< T... > &tp) -> decltype(treePathEntry< sizeof...(T) -1 >(tp))
Returns a copy of the last element of the HybridTreePath.
Definition: treepath.hh:254
constexpr std::size_t treePathSize(const HybridTreePath< T... > &)
Returns the size (number of components) of the given HybridTreePath.
Definition: treepath.hh:196
constexpr auto front(const HybridTreePath< T... > &tp) -> decltype(treePathEntry< 0 >(tp))
Returns a copy of the first element of the HybridTreePath.
Definition: treepath.hh:267
std::ostream & operator<<(std::ostream &os, const HybridTreePath< T... > &tp)
Dumps a HybridTreePath to a stream.
Definition: treepath.hh:424
constexpr auto treePathEntry(const HybridTreePath< T... > &tp, index_constant< i >={}) -> typename std::decay< decltype(std::get< i >(tp._data))>::type
Returns a copy of the i-th element of the HybridTreePath.
Definition: treepath.hh:219
constexpr HybridTreePath< T... > treePath(const T &... t)
Constructs a new HybridTreePath from the given indices.
Definition: treepath.hh:188
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:242
constexpr HybridTreePath< T... > hybridTreePath(const T &... t)
Constructs a new HybridTreePath from the given indices.
Definition: treepath.hh:177
constexpr HybridTreePath< std::size_t, T... > push_front(const HybridTreePath< T... > &tp, std::size_t element)
Prepends a run time index to a HybridTreePath.
Definition: treepath.hh:309
constexpr HybridTreePath< T..., std::size_t > push_back(const HybridTreePath< T... > &tp, std::size_t i)
Appends a run time index to a HybridTreePath.
Definition: treepath.hh:278
void print_tree_path(std::ostream &os)
Definition: treepath.hh:58
Definition: accumulate_static.hh:13
Type
Definition: treepath.hh:30
@ fullyStatic
Definition: treepath.hh:30
@ dynamic
Definition: treepath.hh:30
A hybrid version of TreePath that supports both compile time and run time indices.
Definition: treepath.hh:79
constexpr HybridTreePath(HybridTreePath &&tp)=default
constexpr auto operator[](Dune::index_constant< i > pos) const
Get the index value at position pos.
Definition: treepath.hh:118
constexpr std::size_t element(std::size_t pos) const
Get the index value at position pos.
Definition: treepath.hh:142
constexpr HybridTreePath(std::tuple< T... > t)
Constructor from a std::tuple
Definition: treepath.hh:94
constexpr static std::size_t size()
Get the size (length) of this path.
Definition: treepath.hh:111
constexpr HybridTreePath(U... t)
Constructor from arguments.
Definition: treepath.hh:100
constexpr HybridTreePath()
Default constructor.
Definition: treepath.hh:87
constexpr auto element(Dune::index_constant< i > pos={}) const
Get the last index value.
Definition: treepath.hh:136
constexpr HybridTreePath(const HybridTreePath &tp)=default
constexpr std::size_t operator[](std::size_t pos) const
Get the index value at position pos.
Definition: treepath.hh:124
auto back() const
Get the last index value.
Definition: treepath.hh:153
constexpr static index_sequence enumerate()
Returns an index_sequence for enumerating the components of this HybridTreePath.
Definition: treepath.hh:105
std::index_sequence_for< T... > index_sequence
An index_sequence for the entries in this HybridTreePath.
Definition: treepath.hh:84
Definition: treepath.hh:34
Definition: treepath.hh:37
Definition: treepath.hh:40
Definition: treepath.hh:43
Definition: treepath.hh:46
Definition: treepath.hh:49
Definition: treepath.hh:52
Definition: treepath.hh:55
HybridTreePath< index_constant< i >..., index_constant< k > > type
Definition: treepath.hh:345
HybridTreePath< index_constant< k >, index_constant< i >... > type
Definition: treepath.hh:351
HybridTreePath< index_constant< i >... > type
Definition: treepath.hh:372
HybridTreePath< index_constant< i >... > type
Definition: treepath.hh:386
HybridTreePath< index_constant< i >..., index_constant< k >... > type
Definition: treepath.hh:392