6#ifndef DUNE_TUPLE_UTILITY_HH
7#define DUNE_TUPLE_UTILITY_HH
14#include <dune/common/hybridutilities.hh>
41 template<
class F,
class ArgTuple,
class I, I... i>
42 decltype(
auto)
applyPartial(F&& f, ArgTuple&& args, std::integer_sequence<I, i...> )
44 return f(std::get<i>(args)...);
48 struct TupleAccessTraits
50 typedef typename std::add_const<T>::type& ConstType;
51 typedef T& NonConstType;
52 typedef const typename std::remove_const<T>::type& ParameterType;
56 struct TupleAccessTraits<T*>
58 typedef typename std::add_const<T>::type* ConstType;
59 typedef T* NonConstType;
60 typedef T* ParameterType;
64 struct TupleAccessTraits<T&>
67 typedef T& NonConstType;
68 typedef T& ParameterType;
81 template<
class... Args>
84 typedef std::tuple<Args...> ResultType;
85 static ResultType apply()
87 return ResultType(
static_cast<Args
>(
nullptr)...);
115 template<
template <
class>
class TE,
class T>
118 template<
template <
class>
class TE,
class... Args>
121 typedef std::tuple<typename TE<Args>::Type...> Type;
125 template<
class Tuple,
class Functor, std::size_t... I>
126 inline auto genericTransformTupleBackendImpl(Tuple& t, Functor& f,
const std::index_sequence<I...>& )
127 -> std::tuple<decltype(f(std::get<I>(t)))...>
129 return std::tuple<decltype(f(std::get<I>(t)))...>(f(std::get<I>(t))...);
132 template<
class... Args,
class Functor>
133 auto genericTransformTupleBackend(std::tuple<Args...>& t, Functor& f) ->
134 decltype(genericTransformTupleBackendImpl(t, f,std::index_sequence_for<Args...>{}))
136 return genericTransformTupleBackendImpl(t, f,std::index_sequence_for<Args...>{});
139 template<
class... Args,
class Functor>
140 auto genericTransformTupleBackend(
const std::tuple<Args...>& t, Functor& f) ->
141 decltype(genericTransformTupleBackendImpl(t, f, std::index_sequence_for<Args...>{}))
143 return genericTransformTupleBackendImpl(t, f, std::index_sequence_for<Args...>{});
185 template<
class Tuple,
class Functor>
187 decltype(genericTransformTupleBackend(t, f))
189 return genericTransformTupleBackend(t, f);
224 template<
template<
class>
class TE,
class... Args>
227 mutable std::tuple<Args&...> tup;
229 template<
class T, std::size_t... I>
230 inline auto apply(T&& t,
const std::index_sequence<I...>& ) ->
231 decltype(TE<T>::apply(t,std::get<I>(tup)...))
const
233 return TE<T>::apply(t,std::get<I>(tup)...);
238 struct TypeEvaluator :
public TE<T>
246 inline auto operator()(T&& t) ->
247 decltype(this->apply(t,std::index_sequence_for<Args...>{}))
const
249 return apply(t,std::index_sequence_for<Args...>{});
253 template<
template<
class>
class TE,
class... Args>
291 template<
template<
class>
class TypeEvaluator,
class Tuple,
class... Args>
307 static Type apply(T& t)
321 typedef typename std::remove_reference<T>::type* Type;
322 static Type apply(T& t)
332 typedef typename std::remove_reference<T>::type* Type;
333 static Type apply(T& t)
344 template<
int N,
class Tuple>
347 typedef typename std::tuple_element<std::tuple_size<Tuple>::value - N - 1, Tuple>::type Type;
360 template<
typename Tuple>
361 static typename TupleAccessTraits<typename AtType<N, Tuple>::Type>::NonConstType
364 return std::get<std::tuple_size<Tuple>::value - N - 1>(t);
367 template<
typename Tuple>
368 static typename TupleAccessTraits<typename AtType<N, Tuple>::Type>::ConstType
371 return std::get<std::tuple_size<Tuple>::value - N - 1>(t);
378 template<
class Tuple>
381 template<
typename... Ts>
382 static void apply(std::tuple<Ts...>& t)
411 template<
class Tuple,
template<
class>
class Predicate, std::size_t start = 0,
412 std::size_t
size = std::tuple_size<Tuple>::value>
414 public std::conditional<Predicate<typename std::tuple_element<start,
415 Tuple>::type>::value,
416 std::integral_constant<std::size_t, start>,
417 FirstPredicateIndex<Tuple, Predicate, start+1> >::type
419 static_assert(std::tuple_size<Tuple>::value ==
size,
"The \"size\" "
420 "template parameter of FirstPredicateIndex is an "
421 "implementation detail and should never be set "
426 template<
class Tuple,
template<
class>
class Predicate, std::size_t
size>
430 "types matches the predicate!");
464 template<
class Tuple,
class T, std::
size_t start = 0>
475 template<
class Tuple,
class T>
478 template<
class... Args,
class T>
481 typedef typename std::tuple<Args..., T> type;
490 template<
class Tuple,
class T>
493 template<
class... Args,
class T>
496 typedef typename std::tuple<T, Args...> type;
512 template <
class,
class>
class F,
514 class Seed=std::tuple<>,
515 int N=std::tuple_size<Tuple>::value>
519 typedef typename std::tuple_element<N-1, Tuple>
::type Value;
522 typedef typename F<Accumulated, Value>::type
type;
536 template <
class,
class>
class F,
554 template<
class Head,
class Tail>
569 template<
class Tuple>
Finding the index of a certain type in a std::tuple.
Definition: tupleutility.hh:418
constexpr void forEach(Range &&range, F &&f)
Range based for loop.
Definition: hybridutilities.hh:256
auto transformTuple(Tuple &&orig, Args &&... args) -> decltype(genericTransformTuple(orig, makeTransformTupleFunctor< TypeEvaluator >(args...)))
Definition: tupleutility.hh:292
Seed type
Result of the reduce operation.
Definition: tupleutility.hh:542
ReduceTuple< JoinTuples, Tuple >::type type
Result of the flatten operation.
Definition: tupleutility.hh:573
F< Accumulated, Value >::type type
Result of the reduce operation.
Definition: tupleutility.hh:522
ReduceTuple< PushBackTuple, Tail, Head >::type type
Result of the join operation.
Definition: tupleutility.hh:558
auto genericTransformTuple(Tuple &&t, Functor &&f) -> decltype(genericTransformTupleBackend(t, f))
Definition: tupleutility.hh:186
decltype(auto) applyPartial(F &&f, ArgTuple &&args, std::integer_sequence< I, i... >)
Apply function with arguments from a given tuple.
Definition: tupleutility.hh:42
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
TypeEvaluator to turn a type T into a pointer to T
Definition: tupleutility.hh:320
TypeEvaluator to turn a type T into a reference to T
Definition: tupleutility.hh:305
template which always yields a false value
Definition: typetraits.hh:124
Type for reverse element access.
Definition: tupleutility.hh:346
Reverse element access.
Definition: tupleutility.hh:359
Find the first occurrence of a type in a std::tuple.
Definition: tupleutility.hh:467
Flatten a std::tuple of std::tuple's.
Definition: tupleutility.hh:571
Helper template to clone the type definition of a std::tuple with the storage types replaced by a use...
Definition: tupleutility.hh:116
The actual predicate.
Definition: tupleutility.hh:448
Generator for predicates accepting one particular type.
Definition: tupleutility.hh:445
Join two std::tuple's.
Definition: tupleutility.hh:556
A helper template that initializes a std::tuple consisting of pointers to nullptr.
Definition: tupleutility.hh:79
Deletes all objects pointed to in a std::tuple of pointers.
Definition: tupleutility.hh:380
Helper template to append a type to a std::tuple.
Definition: tupleutility.hh:476
Helper template to prepend a type to a std::tuple.
Definition: tupleutility.hh:491
Apply reduce with meta binary function to template.
Definition: tupleutility.hh:517
Traits for type conversions and type information.