6 #ifndef DUNE_COMMON_HYBRIDMULTIINDEX_HH 7 #define DUNE_COMMON_HYBRIDMULTIINDEX_HH 12 #include <type_traits> 24 constexpr
bool isHybridSizeT()
26 if constexpr (std::is_same_v<T, std::size_t>)
30 if constexpr (
requires { T::value; })
31 return std::is_same_v<T, std::integral_constant<std::size_t, T::value>>;
38 constexpr
auto castToHybridSizeT(T t)
42 using VT =
typename T::value_type;
44 std::is_convertible_v<VT,std::size_t> &&
45 std::is_integral_v<VT> &&
47 "HybridMultiIndex indices must be convertible to std::size_t or std::integral_constant<std::size_t,v>");
48 return std::integral_constant<std::size_t, T::value>{};
50 if constexpr (std::is_integral_v<T>)
53 std::is_convertible_v<T,std::size_t> &&
54 std::is_integral_v<T>,
55 "HybridMultiIndex indices must be convertible to std::size_t or std::integral_constant<std::size_t,v>");
57 "HybridMultiIndex indices must be convertible to std::size_t or std::integral_constant<std::size_t,v>");
58 return std::size_t(t);
62 return std::size_t(0);
79 template<
typename... T>
84 static_assert((... && Impl::isHybridSizeT<T>()),
85 "HybridMultiIndex index storage must be std::size_t or std::integral_constant<std::size_t,v>");
108 template<
typename... I>
109 requires ((
sizeof...(T) > 0 &&
sizeof...(I) ==
sizeof...(T))
112 :
_data(Impl::castToHybridSizeT(
i)...)
122 [[nodiscard]] constexpr
static std::size_t
size()
128 [[nodiscard]] constexpr
static std::size_t
max_size()
139 template<std::
size_t i>
141 [[nodiscard]] constexpr
auto get()
const 143 return std::get<i>(
_data);
147 template<std::
size_t i>
151 return std::get<i>(
_data);
155 [[nodiscard]] constexpr std::size_t operator[](std::size_t pos)
const 157 std::size_t entry = 0;
166 template<std::
size_t i>
168 [[deprecated(
"Method will be removed after Dune 2.11. Use operator[] instead.")]]
171 return std::get<i>(
_data);
175 [[deprecated(
"Method will be removed after Dune 2.11. Use operator[] instead.")]]
176 [[nodiscard]] constexpr std::size_t element(std::size_t pos)
const 178 std::size_t entry = 0;
187 template<std::size_t n =
sizeof...(T)>
188 requires (n > 0 && n ==
sizeof...(T))
189 [[nodiscard]] constexpr
auto front()
const 191 return std::get<0>(
_data);
195 template<std::size_t n =
sizeof...(T)>
196 requires (n > 0 && n ==
sizeof...(T))
197 [[nodiscard]] constexpr
auto back()
const 204 template<
class... Head,
class... Other>
205 friend constexpr
auto join(
const HybridMultiIndex<Head...>&,
const Other&...);
207 std::tuple<T...>
_data;
211 template<
typename... I>
215 template<typename... I>
224 template<typename... T>
226 -> decltype(tp.
back())
237 template<
typename... T>
239 -> decltype(tp.front())
248 template<
typename... T>
271 template<std::size_t
i,
typename... T>
283 template<
typename... T>
306 template<std::size_t
i,
typename... T>
326 template<
typename I,
typename... T>
346 template<
typename I,
typename... T>
348 [[nodiscard]] constexpr
auto accumulate_front(
const HybridMultiIndex<T...>& tp, I
i) {
354 template<
class... Head,
class... Other>
362 constexpr std::size_t
size =
sizeof...(T);
365 }, std::make_index_sequence<size>{});
372 template <
class... T>
378 }, std::make_index_sequence<(
sizeof...(T) - 1)>{});
385 template <
class... T>
387 [[nodiscard]] constexpr
auto pop_back(
const HybridMultiIndex<T...>& tp)
391 }, std::make_index_sequence<(
sizeof...(T) - 1)>{});
403 template <
class... S,
class... T>
408 if constexpr (
sizeof...(S) ==
sizeof...(T)) {
411 return ((lhs[
i] == rhs[
i]) &&...);
427 template <
class S, S... lhs,
class T, T... rhs>
435 return std::bool_constant<result>{};
440 template <
class... S,
class... T>
445 return !(lhs == rhs);
449 template <
class S, S... lhs,
class T, T... rhs>
457 return std::bool_constant<result>{};
461 template<
typename... T>
464 os <<
"HybridMultiIndex< ";
479 template<
typename... T>
482 template <
size_t i,
typename... T>
485 using type = std::tuple_element_t<
i, std::tuple<T...> >;
491 #endif // DUNE_COMMON_HYBRIDMULTIINDEX_HH std::ostream & operator<<(std::ostream &s, const bigunsignedint< k > &x)
Definition: bigunsignedint.hh:301
constexpr auto back(const HybridMultiIndex< T... > &tp) -> decltype(tp.back())
Returns a copy of the last element of the HybridMultiIndex.
Definition: hybridmultiindex.hh:225
constexpr HybridMultiIndex()=default
requires(((std::is_integral_v< I > or Dune::IsIntegralConstant< I >::value) &&...)) HybridMultiIndex(I... i) -> HybridMultiIndex< decltype(Impl::castToHybridSizeT(i))... >
constexpr auto reverse(const HybridMultiIndex< T... > &tp)
Reverses the order of the elements in the multi-index.
Definition: hybridmultiindex.hh:361
decltype(auto) constexpr unpackIntegerSequence(F &&f, [[maybe_unused]] std::integer_sequence< I, i... > sequence)
Unpack an std::integer_sequence<I,i...> to std::integral_constant<I,i>...
Definition: indices.hh:124
HybridMultiIndex(std::tuple< I... >) -> HybridMultiIndex< I... >
constexpr std::integral_constant< std::size_t, sizeof...(II)> size(std::integer_sequence< T, II... >)
Return the size of the sequence.
Definition: integersequence.hh:75
constexpr auto front(const HybridMultiIndex< T... > &tp) -> decltype(tp.front())
Returns a copy of the first element of the HybridMultiIndex.
Definition: hybridmultiindex.hh:238
std::index_sequence_for< T... > index_sequence
An index_sequence for the entries in this HybridMultiIndex.
Definition: hybridmultiindex.hh:90
std::integral_constant< std::size_t, i > index_constant
An index constant with value i.
Definition: indices.hh:29
constexpr HybridMultiIndex(std::tuple< T... > t)
Constructor from a std::tuple
Definition: hybridmultiindex.hh:103
constexpr auto plus
Function object for performing addition.
Definition: hybridutilities.hh:533
constexpr HybridMultiIndex< std::size_t, T... > push_front(const HybridMultiIndex< T... > &tp, std::size_t i)
Prepends a run time index to a HybridMultiIndex.
Definition: hybridmultiindex.hh:284
I i
Definition: hybridmultiindex.hh:328
Dune namespace
Definition: alignedallocator.hh:12
Check if T is an std::integral_constant<I, i>
Definition: typetraits.hh:383
static constexpr index_sequence enumerate()
Returns an index_sequence for enumerating the components of this HybridMultiIndex.
Definition: hybridmultiindex.hh:116
constexpr auto get(std::integer_sequence< T, II... >, std::integral_constant< std::size_t, pos >={})
Return the entry at position pos of the given sequence.
Definition: integersequence.hh:22
constexpr std::integral_constant< T, I0 > head(std::integer_sequence< T, I0, II... >)
For a sequence [head,tail...) return the single head element.
Definition: integersequence.hh:53
std::tuple_element_t< i, std::tuple< T... > > type
Definition: hybridmultiindex.hh:485
Checks whether two types are interoperable.
Definition: typetraits.hh:64
constexpr auto operator!=(const HybridMultiIndex< S... > &lhs, const HybridMultiIndex< T... > &rhs)
Compare two HybridMultiIndexs for inequality.
Definition: hybridmultiindex.hh:441
static constexpr std::size_t max_size()
Get the size (length) of this multi-index.
Definition: hybridmultiindex.hh:128
requires(sizeof...(T) > i) const expr auto get() const
Get the index value at position pos.
Definition: hybridmultiindex.hh:140
constexpr auto join(const HybridMultiIndex< Head... > &head, const Other &... tail)
Join two hybrid multi-indices into one.
Definition: hybridmultiindex.hh:355
requires((sizeof...(T) > 0 &&sizeof...(I)==sizeof...(T)) and((std::is_integral_v< I > or Dune::IsIntegralConstant< I >::value) &&...)) explicit const expr HybridMultiIndex(I... i)
Constructor from arguments.
Definition: hybridmultiindex.hh:109
constexpr bool operator==(const HybridMultiIndex< S... > &lhs, const HybridMultiIndex< T... > &rhs)
Compare two HybridMultiIndexs for value equality.
Definition: hybridmultiindex.hh:404
requires(sizeof...(T) > i) const expr auto operator[](Dune std::tuple< T... > _data
Get the index value at position pos.
Definition: hybridmultiindex.hh:148
A hybrid multi-index class that supports both compile time and run time indices.
Definition: hybridmultiindex.hh:80
static constexpr std::size_t size()
Get the size (length) of this multi-index.
Definition: hybridmultiindex.hh:122
constexpr std::integer_sequence< T, II... > tail(std::integer_sequence< T, I0, II... >)
For a sequence [head,tail...) return the tail sequence.
Definition: integersequence.hh:58
Traits for type conversions and type information.
constexpr void forEach(Range &&range, F &&f)
Range based for loop.
Definition: hybridutilities.hh:261
constexpr HybridMultiIndex & operator=(const HybridMultiIndex &tp)=default
constexpr HybridMultiIndex< T..., std::size_t > push_back(const HybridMultiIndex< T... > &tp, std::size_t i)
Appends a run time index to a HybridMultiIndex.
Definition: hybridmultiindex.hh:249