1#ifndef DUNE_FEM_COMMON_TUPLEUTILITY_HH
2#define DUNE_FEM_COMMON_TUPLEUTILITY_HH
15 template<
class Tuple,
18 class StartType = std::tuple<>
22 static_assert( (begin+length <= std::tuple_size< Tuple >::value),
"Can not cut out tuple of given length" );
26 typedef typename CutOutTuple< Tuple, (begin+1), (length-1), NextType >::type type;
29 template<
class Tuple,
int begin,
class ResultType >
30 struct CutOutTuple< Tuple, begin, 0, ResultType >
32 typedef ResultType type;
45 template< class Tuple, int size = std::tuple_size< Tuple >::value >
48 static_assert( (
size == std::tuple_size< Tuple >::value),
49 "The \"size\" template parameter of PopFrontTuple "
50 "is an implementation detail and should never be "
53 typedef typename CutOutTuple< Tuple, 1, (std::tuple_size< Tuple >::value - 1) >::type type;
56 template<
class Tuple >
57 struct PopFrontTuple< Tuple, 0 >
67 template< class Tuple, int size = std::tuple_size< Tuple >::value >
70 static_assert( (
size == std::tuple_size< Tuple >::value),
71 "The \"size\" template parameter of PopBackTuple "
72 "is an implementation detail and should never be "
75 typedef typename CutOutTuple< Tuple, 0, (std::tuple_size< Tuple >::value - 1) >::type type;
78 template<
class Tuple >
79 struct PopBackTuple< Tuple, 0 >
89 template<
typename T,
typename... Args >
90 inline std::tuple< Args..., T > tuple_push_back (
const std::tuple< Args... > &tup, T t )
92 return std::tuple_cat( tup, std::tuple< T > ( t ) );
100 template<
typename T,
typename... Args >
101 inline std::tuple< T, Args... > tuple_push_front (
const std::tuple< Args... > &tup, T t )
103 return std::tuple_cat( std::tuple< T > ( t ), tup );
111 template<
typename Tup, std::size_t... I >
112 inline auto tuple_pop_back_impl (
const Tup &tup,
const std::index_sequence< I... >& ) ->
113 decltype ( std::make_tuple( std::get< I > ( tup )... ) )
115 return std::make_tuple ( std::get< I > ( tup )... );
118 template<
typename T,
typename... Args >
119 inline auto tuple_pop_back (
const std::tuple< T, Args... > &tup ) ->
120 decltype ( tuple_pop_back_impl ( tup , std::make_index_sequence<
sizeof...( Args ) > ( ) ) )
122 return tuple_pop_back_impl ( tup , std::make_index_sequence<
sizeof... ( Args ) > ( ) );
130 template<
typename Tup, std::size_t... I >
131 inline auto tuple_pop_front_impl (
const Tup &tup,
const std::index_sequence< I... >& ) ->
132 decltype ( std::make_tuple( std::get< I > ( tup )... ) )
134 return std::make_tuple ( std::get< I + 1 > ( tup )... );
137 template<
typename T,
typename... Args >
138 inline auto tuple_pop_front (
const std::tuple< T, Args... > &tup ) ->
139 decltype ( tuple_pop_front_impl ( tup , std::make_index_sequence<
sizeof...( Args ) > ( ) ) )
141 return tuple_pop_front_impl ( tup , std::make_index_sequence<
sizeof... ( Args ) > ( ) );
155 template<
class Tuple,
157 int N = std::tuple_size< Tuple >::value
161 static const bool value = ( std::is_same<
typename std::tuple_element< N-1, Tuple >::type, Type >::value
162 || ContainsType< Tuple, Type, N-1 >::value );
165 template<
class Tuple,
168 struct ContainsType< Tuple, Type, 0 >
170 static const bool value =
false;
181 template<
class Tuple,
183 class Seed = std::tuple<>,
185 int size = std::tuple_size< SubTuple >::value
187 class FirstTypeIndexTuple
189 static_assert( (index == std::tuple_size< Seed >::value),
190 "The \"index\" template parameter of FirstTypeIndexTuple"
191 "is an implementation detail and should never be "
195 typedef typename std::tuple_element< index, SubTuple >::type Element;
203 typedef typename FirstTypeIndexTuple< Tuple, SubTuple, NextSeed, (index+1) >::type type;
206 template<
class Tuple,
211 struct FirstTypeIndexTuple< Tuple, SubTuple, Seed,
size,
size >
224 template<
class Tuple,
226 class Seed = std::tuple<>,
228 int size = std::tuple_size< Positions >::value
232 template<
class,
class,
class,
int,
int >
friend class MakeSubTuple;
235 static const int position = std::tuple_element< index, Positions >::type::value;
238 typedef typename std::tuple_element< position, Tuple >::type AppendType;
242 typedef MakeSubTuple< Tuple, Positions, AccumulatedType, (index+1),
size > NextType;
244 static typename NextType::type append ( Tuple &tuple, Seed &seed )
246 AppendType append = std::get< position >( tuple );
247 AccumulatedType next = tuple_push_back( seed, append );
248 return NextType::append( tuple, next );
252 typedef typename NextType::type type;
254 static type apply ( Tuple &tuple )
257 return append( tuple, seed );
261 template<
class Tuple,
265 class MakeSubTuple< Tuple, Positions, Seed,
size,
size >
267 template<
class,
class,
class,
int,
int >
friend class MakeSubTuple;
269 static Seed append ( Tuple &tuple, Seed &seed ) {
return seed; }
274 static type apply ( Tuple & ) {
return type(); }
285 template<
class VectorTupleType,
int pos >
291 typedef typename VectorTupleType::value_type TupleType;
292 typedef typename std::tuple_element< pos, TupleType >::type ValueType;
293 typedef ValueType value_type;
304 assert( i <
size() );
305 return get< pos >( vector_[ i ] );
312 assert( i <
size() );
313 return get< pos >( vector_[ i ] );
317 size_t size ()
const {
return vector_.size(); }
320 VectorTupleType &vector_;
342 template<
class Tuple,
344 class Seed = std::tuple<>,
345 int len = std::tuple_size< Tuple >::value
353 static Tuple
apply (
const Key &key = Key() )
356 return append( key, seed );
362 static Tuple append (
const Key &key, Seed &seed )
364 static const int index = std::tuple_size< Tuple >::value - len;
366 typedef typename std::tuple_element< index, Tuple >::type AppendType;
369 AccumulatedType next = Dune::tuple_push_back< AppendType >( seed, AppendType( key ) );
374 template<
class Tuple,
class Key,
class Seed >
375 struct InstantiateTuple< Tuple, Key, Seed, 0 >
377 static Tuple
apply (
const Key &key = Key() ) {
return Tuple(); }
380 template<
class,
class,
class,
int >
friend struct InstantiateTuple;
382 static Seed append (
const Key &key, Seed &seed ) {
return seed; }
wrapper class to convert a vector of tuples of RangeTypes into something that behaves like a vector< ...
Definition: tupleutility.hh:287
size_t size() const
return size of vector
Definition: tupleutility.hh:317
TupleToVectorConverter(VectorTupleType &vector)
constructor
Definition: tupleutility.hh:296
ValueType & operator[](const size_t i)
return reference to i-th entry of vector and pos's tuple component
Definition: tupleutility.hh:301
Contains utility classes which can be used with std::tuple.
Dune namespace.
Definition: alignedallocator.hh:13
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
Find the first occurrence of a type in a std::tuple.
Definition: tupleutility.hh:467
Instantiate a tuple of elements with identical, simple constructors.
Definition: tupleutility.hh:348
static Tuple apply(const Key &key=Key())
create tuple instance
Definition: tupleutility.hh:353
Helper template to append a type to a std::tuple.
Definition: tupleutility.hh:476