Loading...
Searching...
No Matches
treepath.hh
Go to the documentation of this file.
// -*- tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=8 sw=2 sts=2:
// SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root
// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-GPL-2.0-only-with-PDELab-exception
#ifndef DUNE_TYPETREE_TREEPATH_HH
#define DUNE_TYPETREE_TREEPATH_HH
#include <cstddef>
#include <cassert>
#include <iostream>
#include <type_traits>
#include <dune/common/documentation.hh>
#include <dune/common/typetraits.hh>
#include <dune/common/indices.hh>
#include <dune/common/typetree/treepath.hh>
namespace Dune {
namespace TypeTree {
// The Impl namespace collects some free standing functions helper functions
namespace Impl {
template<class T>
constexpr bool isHybridSizeT()
{
if constexpr (std::is_same_v<T, std::size_t>)
return true;
else
{
if constexpr (requires { T::value; })
return std::is_same_v<T, std::integral_constant<std::size_t, T::value>>;
else
return false;
}
}
template<class T>
constexpr auto castToHybridSizeT(T t)
{
if constexpr (Dune::IsIntegralConstant<T>::value)
{
using VT = typename T::value_type;
static_assert(
std::is_convertible_v<VT,std::size_t> &&
std::is_integral_v<VT> &&
T::value >= 0,
"HybridTreePath indices must be convertible to std::size_t or std::integral_constant<std::size_t,v>");
return std::integral_constant<std::size_t, T::value>{};
} else {
static_assert(
std::is_convertible_v<T,std::size_t> &&
std::is_integral_v<T>,
"HybridTreePath indices must be convertible to std::size_t or std::integral_constant<std::size_t,v>");
assert(t >= 0 &&
"HybridTreePath indices must be convertible to std::size_t or std::integral_constant<std::size_t,v>");
return std::size_t(t);
}
}
}
template<typename... T>
using HybridTreePath = Dune::HybridMultiIndex<T...>;
template<typename... T>
requires (((std::is_integral_v<T> or Dune::IsIntegralConstant<T>::value) && ...))
[[nodiscard]] constexpr auto hybridTreePath(const T&... t)
{
return HybridMultiIndex(t...);
}
namespace TreePathType {
enum Type { fullyStatic, dynamic };
}
template<typename>
struct TreePathSize;
template<typename,std::size_t>
struct TreePathPushBack;
template<typename,std::size_t>
struct TreePathPushFront;
template<typename>
struct TreePathBack;
template<typename>
struct TreePathFront;
template<typename, std::size_t...>
struct TreePathPopBack;
template<typename>
struct TreePathPopFront;
template<typename, typename>
struct TreePathConcat;
template<std::size_t... i>
[[deprecated("This function will be removed after Dune 2.11.")]]
void print_tree_path(std::ostream& os)
{}
template<std::size_t k, std::size_t... i>
[[deprecated("This function will be removed after Dune 2.11.")]]
void print_tree_path(std::ostream& os)
{
os << k << " ";
print_tree_path<i...>(os);
}
template<typename... T>
requires (((std::is_integral_v<T> or Dune::IsIntegralConstant<T>::value) && ...))
[[nodiscard]] constexpr auto makeTreePath(const T... t)
{
return HybridMultiIndex(t...);
}
template<typename... T>
[[nodiscard]] constexpr std::size_t treePathSize(const HybridTreePath<T...>&)
{
return sizeof...(T);
}
template<std::size_t i, typename... T>
[[nodiscard]] constexpr auto treePathEntry(const HybridTreePath<T...>& tp, index_constant<i> = {})
{
return tp[index_constant<i>{}];
}
template<std::size_t i,typename... T>
[[deprecated("This function will be removed after Dune 2.11. Use operator[] instead.")]]
[[nodiscard]] constexpr std::size_t treePathIndex(const HybridTreePath<T...>& tp, index_constant<i> = {})
{
return tp[index_constant<i>{}];
}
template<std::size_t... i>
struct
[[deprecated("This class will be removed after Dune 2.11. Use the size() member function instead.")]]
TreePathSize<HybridTreePath<index_constant<i>...> >
: public index_constant<sizeof...(i)>
{};
template<std::size_t k, std::size_t... i>
struct
[[deprecated("This class will be removed after Dune 2.11. Use the free push_back() function instead.")]]
TreePathPushBack<HybridTreePath<index_constant<i>...>,k>
{
typedef HybridTreePath<index_constant<i>...,index_constant<k>> type;
};
template<std::size_t k, std::size_t... i>
struct
[[deprecated("This class will be removed after Dune 2.11. Use the free push_front() function instead.")]]
TreePathPushFront<HybridTreePath<index_constant<i>...>,k>
{
typedef HybridTreePath<index_constant<k>,index_constant<i>...> type;
};
template<std::size_t k>
struct
[[deprecated("This class will be removed after Dune 2.11. Use the back() member function instead.")]]
TreePathBack<HybridTreePath<index_constant<k>>>
: public index_constant<k>
{};
template<std::size_t j, std::size_t k, std::size_t... l>
struct
[[deprecated("This class will be removed after Dune 2.11. Use the back() member function instead.")]]
TreePathBack<HybridTreePath<index_constant<j>,index_constant<k>,index_constant<l>...>>
: public TreePathBack<HybridTreePath<index_constant<k>,index_constant<l>...>>
{};
template<std::size_t k, std::size_t... i>
struct
[[deprecated("This class will be removed after Dune 2.11. Use the front() member function instead.")]]
TreePathFront<HybridTreePath<index_constant<k>,index_constant<i>...>>
: public index_constant<k>
{};
template<std::size_t k, std::size_t... i>
struct
[[deprecated("This class will be removed after Dune 2.11. Use the free pop_back() function instead.")]]
TreePathPopBack<HybridTreePath<index_constant<k>>,i...>
{
typedef HybridTreePath<index_constant<i>...> type;
};
template<std::size_t j,
std::size_t k,
std::size_t... l,
std::size_t... i>
struct
[[deprecated("This class will be removed after Dune 2.11. Use the free pop_back() function instead.")]]
TreePathPopBack<HybridTreePath<index_constant<j>,index_constant<k>,index_constant<l>...>,i...>
: public TreePathPopBack<HybridTreePath<index_constant<k>,index_constant<l>...>,i...,j>
{};
template<std::size_t k, std::size_t... i>
struct
[[deprecated("This class will be removed after Dune 2.11. Use the free pop_front() function instead.")]]
TreePathPopFront<HybridTreePath<index_constant<k>,index_constant<i>...> >
{
typedef HybridTreePath<index_constant<i>...> type;
};
template<std::size_t... i, std::size_t... k>
struct
[[deprecated("This class will be removed after Dune 2.11. Use the free join() function instead.")]]
TreePathConcat<HybridTreePath<index_constant<i>...>,HybridTreePath<index_constant<k>...> >
{
typedef HybridTreePath<index_constant<i>...,index_constant<k>...> type;
};
template<std::size_t... i>
using StaticTreePath = HybridTreePath<Dune::index_constant<i>...>;
} // namespace TypeTree
} //namespace Dune
#endif // DUNE_TYPETREE_TREEPATH_HH
Dune::TypeTree::treePathEntry
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
Dune::TypeTree::treePathSize
constexpr std::size_t treePathSize(const HybridTreePath< T... > &)
Returns the size (number of components) of the given HybridTreePath.
Definition treepath.hh:191
Dune::TypeTree::makeTreePath
constexpr auto makeTreePath(const T... t)
helper function to construct a new HybridTreePath from the given indices.
Definition treepath.hh:184
Dune::TypeTree::hybridTreePath
constexpr auto hybridTreePath(const T &... t)
Constructs a new HybridTreePath from the given indices.
Definition treepath.hh:102
Dune::TypeTree::HybridTreePath
Dune::HybridMultiIndex< T... > HybridTreePath
A type for representing tree paths that supports both compile time and run time indices.
Definition treepath.hh:85
Dune::TypeTree::treePathIndex
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::TypeTree::StaticTreePath
HybridTreePath< Dune::index_constant< i >... > StaticTreePath
Definition treepath.hh:324
Dune::TypeTree::print_tree_path
void print_tree_path(std::ostream &os)
Definition treepath.hh:161
Dune
Definition accumulate_static.hh:17
Dune::TypeTree
Definition accumulate_static.hh:18
Dune::TypeTree::TreePathType
Definition treepath.hh:107
Dune::TypeTree::TreePathType::Type
Type
Definition treepath.hh:108
Dune::TypeTree::TreePathType::fullyStatic
@ fullyStatic
Definition treepath.hh:108
Dune::TypeTree::TreePathType::dynamic
@ dynamic
Definition treepath.hh:108
Dune::TypeTree::TreePathSize
Definition treepath.hh:115
Dune::TypeTree::TreePathPushBack
Definition treepath.hh:121
Dune::TypeTree::TreePathPushFront
Definition treepath.hh:127
Dune::TypeTree::TreePathBack
Definition treepath.hh:133
Dune::TypeTree::TreePathFront
Definition treepath.hh:139
Dune::TypeTree::TreePathPopBack
Definition treepath.hh:145
Dune::TypeTree::TreePathPopFront
Definition treepath.hh:151
Dune::TypeTree::TreePathConcat
Definition treepath.hh:157
Dune::TypeTree::TreePathPushBack< HybridTreePath< index_constant< i >... >, k >::type
HybridTreePath< index_constant< i >..., index_constant< k > > type
Definition treepath.hh:257
Dune::TypeTree::TreePathPushFront< HybridTreePath< index_constant< i >... >, k >::type
HybridTreePath< index_constant< k >, index_constant< i >... > type
Definition treepath.hh:265
Dune::TypeTree::TreePathPopBack< HybridTreePath< index_constant< k > >, i... >::type
HybridTreePath< index_constant< i >... > type
Definition treepath.hh:294
Dune::TypeTree::TreePathPopFront< HybridTreePath< index_constant< k >, index_constant< i >... > >::type
HybridTreePath< index_constant< i >... > type
Definition treepath.hh:312
Dune::TypeTree::TreePathConcat< HybridTreePath< index_constant< i >... >, HybridTreePath< index_constant< k >... > >::type
HybridTreePath< index_constant< i >..., index_constant< k >... > type
Definition treepath.hh:320