6#ifndef DUNE_COMMON_HYBRIDMULTIINDEX_HH
7#define DUNE_COMMON_HYBRIDMULTIINDEX_HH
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)
40 if constexpr (Dune::IsIntegralConstant<T>::value)
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);
60 if constexpr (not (Dune::IsIntegralConstant<T>::value or std::is_integral_v<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>
140 requires (
sizeof...(T) > i)
141 [[nodiscard]]
constexpr auto get()
const
143 return std::get<i>(_data);
147 template<std::
size_t i>
148 requires (
sizeof...(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>
167 requires (
sizeof...(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
199 return std::get<n-1>(_data);
204 template<
class... Head,
class... 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>
327 requires (
sizeof...(T) > 0)
346 template<
typename I,
typename... T>
347 requires (
sizeof...(T) > 0)
354 template<
class... Head,
class... Other>
362 constexpr std::size_t
size =
sizeof...(T);
365 }, std::make_index_sequence<size>{});
372 template <
class... T>
373 requires (
sizeof...(T) > 0)
378 }, std::make_index_sequence<(
sizeof...(T) - 1)>{});
385 template <
class... T>
386 requires (
sizeof...(T) > 0)
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>
480 struct tuple_size<
Dune::HybridMultiIndex<T...>> :
public std::integral_constant<std::size_t,sizeof...(T)> {};
482 template <
size_t i,
typename... T>
483 struct tuple_element<i,
Dune::HybridMultiIndex<T...> >
485 using type = std::tuple_element_t<i, std::tuple<T...> >;
Traits for type conversions and type information.
decltype(auto) constexpr unpackIntegerSequence(F &&f, std::integer_sequence< I, i... > sequence)
Unpack an std::integer_sequence<I,i...> to std::integral_constant<I,i>...
Definition indices.hh:124
std::integral_constant< std::size_t, i > index_constant
An index constant with value i.
Definition indices.hh:29
constexpr void forEach(Range &&range, F &&f)
Range based for loop.
Definition hybridutilities.hh:261
constexpr auto plus
Function object for performing addition.
Definition hybridutilities.hh:533
std::ostream & operator<<(std::ostream &s, const bigunsignedint< k > &x)
Definition bigunsignedint.hh:301
Dune namespace
Definition alignedallocator.hh:13
HybridMultiIndex(I... i) -> HybridMultiIndex< decltype(Impl::castToHybridSizeT(i))... >
constexpr auto join(const HybridMultiIndex< Head... > &head, const Other &... tail)
Join two hybrid multi-indices into one.
Definition hybridmultiindex.hh:355
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 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 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< 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
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 operator!=(const HybridMultiIndex< S... > &lhs, const HybridMultiIndex< T... > &rhs)
Compare two HybridMultiIndexs for inequality.
Definition hybridmultiindex.hh:441
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
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
constexpr auto front(const HybridMultiIndex< T... > &tp) -> decltype(tp.front())
Returns a copy of the first element of the HybridMultiIndex.
Definition hybridmultiindex.hh:238
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
constexpr bool operator==(const HybridMultiIndex< S... > &lhs, const HybridMultiIndex< T... > &rhs)
Compare two HybridMultiIndexs for value equality.
Definition hybridmultiindex.hh:404
A hybrid multi-index class that supports both compile time and run time indices.
Definition hybridmultiindex.hh:81
static constexpr std::size_t size()
Get the size (length) of this multi-index.
Definition hybridmultiindex.hh:122
static constexpr std::size_t max_size()
Get the size (length) of this multi-index.
Definition hybridmultiindex.hh:128
constexpr HybridMultiIndex()=default
constexpr auto front() const
Get the first index value. Only available in non-empty multi-indices.
Definition hybridmultiindex.hh:189
constexpr HybridMultiIndex(const HybridMultiIndex &tp)=default
static constexpr index_sequence enumerate()
Returns an index_sequence for enumerating the components of this HybridMultiIndex.
Definition hybridmultiindex.hh:116
constexpr HybridMultiIndex(HybridMultiIndex &&tp)=default
friend constexpr auto join(const HybridMultiIndex< Head... > &, const Other &...)
constexpr auto get() const
Get the index value at position pos.
Definition hybridmultiindex.hh:141
constexpr HybridMultiIndex(std::tuple< T... > t)
Constructor from a std::tuple.
Definition hybridmultiindex.hh:103
constexpr auto back() const
Get the last index value. Only available in non-empty multi-indices.
Definition hybridmultiindex.hh:197
constexpr auto element(Dune::index_constant< i > pos={}) const
Get the last index value.
Definition hybridmultiindex.hh:169
constexpr HybridMultiIndex & operator=(HybridMultiIndex &&tp)=default
constexpr HybridMultiIndex & operator=(const HybridMultiIndex &tp)=default
std::index_sequence_for< T... > index_sequence
An index_sequence for the entries in this HybridMultiIndex.
Definition hybridmultiindex.hh:90
constexpr std::size_t operator[](std::size_t pos) const
Get the index value at position pos.
Definition hybridmultiindex.hh:155
constexpr HybridMultiIndex(I... i)
Constructor from arguments.
Definition hybridmultiindex.hh:111
constexpr std::size_t element(std::size_t pos) const
Get the index value at position pos.
Definition hybridmultiindex.hh:176
std::tuple_element_t< i, std::tuple< T... > > type
Definition hybridmultiindex.hh:485
static constexpr bool value
True if either a conversion from T1 to T2 or vice versa exists.
Definition typetraits.hh:70
Check if T is an std::integral_constant<I, i>.
Definition typetraits.hh:384