1#ifndef __DUNE_ACFEM_MPL_ACCESS_HH__
2#define __DUNE_ACFEM_MPL_ACCESS_HH__
7#include <dune/common/hybridutilities.hh>
8#include "../common/types.hh"
9#include "generators.hh"
11#include "typepackelement.hh"
41 template<std::
size_t N,
class Seq>
44#if DUNE_ACFEM_IS_CLANG(5,99)
45# define DUNE_ACFEM_GET_IS_FAST true
46 static_assert(__has_builtin(__type_pack_element),
"");
48 template<std::size_t N,
class I, I... Is>
50 : __type_pack_element<N, Constant<I, Is>...>
53 template<std::size_t N,
class I, I I0, I... IRest>
55 :
Get<N-1, Sequence<I, IRest...> >
58 template<
class I, I I0, I... IRest>
59 struct Get<0,
Sequence<I, I0, IRest...> >
64 template<
class I, I I0, I I1, I... IRest>
65 struct Get<1,
Sequence<I, I0, I1, IRest...> >
69 template<
class I, I I0, I I1, I I2, I... IRest>
70 struct Get<2,
Sequence<I, I0, I1, I2, IRest...> >
74 template<
class I, I I0, I I1, I I2, I I3, I... IRest>
75 struct Get<3,
Sequence<I, I0, I1, I2, I3, IRest...> >
79 template<
class I, I I0, I I1, I I2, I I3, I I4, I... IRest>
80 struct Get<4,
Sequence<I, I0, I1, I2, I3, I4, IRest...> >
84 template<
class I, I I0, I I1, I I2, I I3, I I4, I I5, I... IRest>
85 struct Get<5,
Sequence<I, I0, I1, I2, I3, I4, I5, IRest...> >
89 template<
class I, I I0, I I1, I I2, I I3, I I4, I I5, I I6, I... IRest>
90 struct Get<6,
Sequence<I, I0, I1, I2, I3, I4, I5, I6, IRest...> >
94 template<
class I, I I0, I I1, I I2, I I3, I I4, I I5, I I6, I I7, I... IRest>
95 struct Get<7,
Sequence<I, I0, I1, I2, I3, I4, I5, I6, I7, IRest...> >
99 template<
class I, I I0, I I1, I I2, I I3, I I4, I I5, I I6, I I7, I I8, I... IRest>
100 struct Get<8,
Sequence<I, I0, I1, I2, I3, I4, I5, I6, I7, I8, IRest...> >
104 template<
class I, I I0, I I1, I I2, I I3, I I4, I I5, I I6, I I7, I I8, I I9, I... IRest>
105 struct Get<9,
Sequence<I, I0, I1, I2, I3, I4, I5, I6, I7, I8, I9, IRest...> >
118 template<
class I, I I0>
124 template<std::
size_t N,
class TupleLike>
125 using TupleElement = std::tuple_element_t<N, std::decay_t<TupleLike> >;
128 template<std::size_t I, class T, std::enable_if_t<IsTupleLike<T>::value,
int> = 0>
131 return std::get<I>(std::forward<T>(t));
135 template<std::size_t I, class T, std::size_t N, std::enable_if_t<std::is_integral<T>::value,
int> = 0>
142 template<std::size_t I,
class T, T... V>
145 return Get<I,
Sequence<T, V...> >::value;
149 template<std::
size_t I,
class T, T V>
152 static_assert(I == 0,
"Integral constants only have one value.");
156 template<
class T,
class SFINAE =
void>
162 struct AllowsGet<T,
std::enable_if_t<(size<T>() != size<void>())> >
167 template<
class SequenceLike>
168 using Head = Get<0, SequenceLike>;
171 template<
class SequenceLike>
179 template<std::
size_t Skip,
class Sequence,
class SFINAE =
void>
180 struct GetTailPartHelper;
183 struct GetTailPartHelper<0, Seq>
188 template<std::size_t Skip,
class T, T I0, T... I>
189 struct GetTailPartHelper<Skip,
Sequence<T, I0, I...>,
std::enable_if_t<(Skip > 0)> >
191 using Type =
typename GetTailPartHelper<Skip-1,
Sequence<T, I...> >::Type;
194 template<std::
size_t Cnt,
class Input,
class Output = Sequence<
typename Input::value_type>,
class SFINAE =
void>
195 struct GetHeadPartHelper;
197 template<
class Input,
class Output>
198 struct GetHeadPartHelper<0, Input, Output>
203 template<std::size_t Cnt,
class T, T I0, T... I, T... O>
204 struct GetHeadPartHelper<Cnt,
Sequence<T, I0, I...>,
Sequence<T, O...>,
std::enable_if_t<(Cnt > 0)> >
206 using Type =
typename GetHeadPartHelper<Cnt-1,
Sequence<T, I...>,
Sequence<T, O..., I0> >::Type;
212 template<std::
size_t Skip, std::
size_t Cnt,
class Seq>
213 using GetPart =
typename GetHeadPartHelper<Cnt, typename GetTailPartHelper<Skip, Seq>::Type>::Type;
216 template<std::
size_t Cnt,
class Seq>
217 using HeadPart =
typename GetHeadPartHelper<Cnt, Seq>::Type;
220 template<std::
size_t Cnt,
class Seq>
227 template<std::
size_t HeadSize,
class T, T V,
class Seq>
230 static constexpr std::size_t value = std::numeric_limits<std::size_t>::max();
234 template<std::size_t HeadSize,
class T, T V, T... Ints>
235 struct IndexInHelper<HeadSize, T, V,
Sequence<T, V, Ints...> >
237 static constexpr std::size_t value = HeadSize;
241 template<std::size_t HeadSize,
class T, T V, T I, T... Ints>
242 struct IndexInHelper<HeadSize, T, V,
Sequence<T, I, Ints...> >
244 static constexpr std::size_t value =
245 IndexInHelper<HeadSize+1, T, V,
Sequence<T, Ints...> >::value;
250 template<
class T, T... I, T V>
251 constexpr auto multiplicity(Sequence<T, I...>, Constant<T, V>)
253 return IndexConstant<((std::size_t)(I == V) + ... + 0)>::value;
256 template<
class T, T... I>
257 constexpr bool containsValue(Sequence<T, I...>, T V)
259 return (... || (I == V));
263 template<
class T, T... I, T V, std::size_t... Idx>
264 constexpr auto indexInHelper(Sequence<T, I...>, Constant<T, V>, IndexSequence<Idx...>)
266 return IndexConstant<((std::size_t)((I == V)*Idx) + ... + 0)>::value;
269 template<
class T, T... I, T V>
270 constexpr auto indexIn(Sequence<T, I...>, Constant<T, V>)
273 return IndexConstant<((std::size_t)((I == V)*Idx) + ... + 0)>::value;
278 template<
class Seq,
typename Seq::value_type V>
283 template<
class Seq,
typename Seq::value_type V>
286 template<
class Seq,
typename Seq::value_type V>
287 constexpr inline bool ContainsValueV = containsValue(Seq{}, V);
289 template<
class Seq,
typename Seq::value_type V>
290 using ContainsValue =
BoolConstant<containsValue(Seq{}, V)>;
294 template<std::ptrdiff_t V,
class T, T... I>
301 template<std::ptrdiff_t V,
class T, T... I>
308 template<std::ptrdiff_t V,
class Seq>
312 template<std::ptrdiff_t V,
class Seq>
316 template<std::
size_t V, std::
size_t N,
class Head,
class Tail>
319 template<std::size_t V, std::size_t N, std::size_t... Head, std::size_t Tail0, std::size_t... Tail>
325 template<std::size_t V, std::size_t... Head, std::size_t Tail0, std::size_t... Tail>
333 template<std::
size_t V, std::
size_t N,
class Input>
334 using Put =
typename PutHelper<V, N, IndexSequence<>, Input>::Type;
constexpr decltype(auto) get(T &&t, IndexConstant< I >=IndexConstant< I >{})
Access to the i-the element.
Definition: access.hh:129
constexpr auto pushBack(Sequence< T, I... >, IntConstant< V >=IntConstant< V >{})
Add V at the end of the sequece.
Definition: access.hh:302
typename PutHelper< V, N, IndexSequence<>, Input >::Type Put
Replace value at position N with V.
Definition: access.hh:334
typename GetHeadPartHelper< Cnt, Seq >::Type HeadPart
Extract Cnt many consecutive elements from the front of Seq.
Definition: access.hh:217
std::tuple_element_t< N, std::decay_t< TupleLike > > TupleElement
Forward to std::tuple_element<N, std::decay_t<T> >
Definition: access.hh:125
decltype(pushFront< V >(Seq{})) PushFront
Add value to start of integer-sequence.
Definition: access.hh:309
typename GetHeadPartHelper< Cnt, typename GetTailPartHelper< Skip, Seq >::Type >::Type GetPart
Extract Cnt many consecutive elements from Seq starting at position N.
Definition: access.hh:213
typename GetTailPartHelper< Seq::size() -Cnt, Seq >::Type TailPart
Extract Cnt many consecutive elements from the end of Seq.
Definition: access.hh:221
constexpr std::size_t size()
Gives the number of elements in tuple-likes and std::integer_sequence.
Definition: size.hh:73
IndexConstant< IndexInHelper< 0, typename Seq::value_type, V, Seq >::value > IndexIn
Find the index of a given value in a sequence.
Definition: access.hh:279
constexpr auto pushFront(Sequence< T, I... >, IntConstant< V >=IntConstant< V >{})
Add V at the front of the sequence.
Definition: access.hh:295
decltype(pushBack< V >(Seq{})) PushBack
Add value to end of integer-sequence.
Definition: access.hh:313
Constant< std::ptrdiff_t, V > IntConstant
Short-for integral constant of type std::p0trdiff_t.
Definition: types.hh:52
Sequence< std::size_t, V... > IndexSequence
Sequence of std::size_t values.
Definition: types.hh:64
integral_constant< T, V > Constant
Short-cut for any integral constant.
Definition: types.hh:40
Constant< bool, V > BoolConstant
Short-cut for integral constant of type bool.
Definition: types.hh:48
std::integer_sequence< T, V... > Sequence
Sequence of any type of integer values.
Definition: types.hh:56
Constant< std::size_t, V > IndexConstant
Short-cut for integral constant of type std::size_t.
Definition: types.hh:44
BoolConstant< false > FalseType
Alias for std::false_type.
Definition: types.hh:110
BoolConstant< true > TrueType
Alias for std::true_type.
Definition: types.hh:107
Gets the type of the n-th element of a tuple-like or the std::integral_constant corresponding to the ...
Definition: access.hh:42