4#ifndef DUNE_TUPLE_UTILITY_HH
5#define DUNE_TUPLE_UTILITY_HH
11#include <dune/common/hybridutilities.hh>
12#include <dune/common/std/type_traits.hh>
13#include <dune/common/std/utility.hh>
39 template<
class F,
class ArgTuple,
class I, I... i>
40 decltype(
auto)
applyPartial(F&& f, ArgTuple&& args, std::integer_sequence<I, i...> )
42 return f(std::get<i>(args)...);
46 struct TupleAccessTraits
48 typedef typename std::add_const<T>::type& ConstType;
49 typedef T& NonConstType;
50 typedef const typename std::remove_const<T>::type& ParameterType;
54 struct TupleAccessTraits<T*>
56 typedef typename std::add_const<T>::type* ConstType;
57 typedef T* NonConstType;
58 typedef T* ParameterType;
62 struct TupleAccessTraits<T&>
65 typedef T& NonConstType;
66 typedef T& ParameterType;
79 template<
class... Args>
82 typedef std::tuple<Args...> ResultType;
83 static ResultType
apply()
85 return ResultType(
static_cast<Args
>(
nullptr)...);
113 template<
template <
class>
class TE,
class T>
116 template<
template <
class>
class TE,
class... Args>
119 typedef std::tuple<typename TE<Args>::Type...> Type;
123 template<
class Tuple,
class Functor, std::size_t... I>
124 inline auto genericTransformTupleBackendImpl(Tuple& t, Functor& f,
const Std::index_sequence<I...>& )
125 -> std::tuple<decltype(f(std::get<I>(t)))...>
127 return std::tuple<decltype(f(std::get<I>(t)))...>(f(std::get<I>(t))...);
130 template<
class... Args,
class Functor>
131 auto genericTransformTupleBackend(std::tuple<Args...>& t, Functor& f) ->
132 decltype(genericTransformTupleBackendImpl(t, f,Std::index_sequence_for<Args...>{}))
134 return genericTransformTupleBackendImpl(t, f,Std::index_sequence_for<Args...>{});
137 template<
class... Args,
class Functor>
138 auto genericTransformTupleBackend(
const std::tuple<Args...>& t, Functor& f) ->
139 decltype(genericTransformTupleBackendImpl(t, f, Std::index_sequence_for<Args...>{}))
141 return genericTransformTupleBackendImpl(t, f, Std::index_sequence_for<Args...>{});
183 template<
class Tuple,
class Functor>
185 decltype(genericTransformTupleBackend(t, f))
187 return genericTransformTupleBackend(t, f);
222 template<
template<
class>
class TE,
class... Args>
225 mutable std::tuple<Args&...> tup;
227 template<
class T, std::size_t... I>
228 inline auto apply(T&& t,
const Std::index_sequence<I...>& ) ->
236 struct TypeEvaluator :
public TE<T>
244 inline auto operator()(T&& t) ->
251 template<
template<
class>
class TE,
class... Args>
289 template<
template<
class>
class TypeEvaluator,
class Tuple,
class... Args>
305 static Type apply(T& t)
319 typedef typename std::remove_reference<T>::type* Type;
320 static Type apply(T& t)
330 typedef typename std::remove_reference<T>::type* Type;
331 static Type
apply(T& t)
342 template<
int N,
class Tuple>
345 typedef typename std::tuple_element<std::tuple_size<Tuple>::value - N - 1, Tuple>::type Type;
358 template<
typename Tuple>
359 static typename TupleAccessTraits<typename AtType<N, Tuple>::Type>::NonConstType
362 return std::get<std::tuple_size<Tuple>::value - N - 1>(t);
365 template<
typename Tuple>
366 static typename TupleAccessTraits<typename AtType<N, Tuple>::Type>::ConstType
369 return std::get<std::tuple_size<Tuple>::value - N - 1>(t);
376 template<
class Tuple>
379 template<
typename... Ts>
380 static void apply(std::tuple<Ts...>& t)
409 template<
class Tuple,
template<
class>
class Predicate, std::size_t start = 0,
410 std::size_t size = std::tuple_size<Tuple>::value>
412 public std::conditional<Predicate<typename std::tuple_element<start,
413 Tuple>::type>::value,
414 std::integral_constant<std::size_t, start>,
415 FirstPredicateIndex<Tuple, Predicate, start+1> >::type
417 static_assert(std::tuple_size<Tuple>::value == size,
"The \"size\" "
418 "template parameter of FirstPredicateIndex is an "
419 "implementation detail and should never be set "
424 template<
class Tuple,
template<
class>
class Predicate, std::size_t size>
428 "types matches the predicate!");
462 template<
class Tuple,
class T, std::
size_t start = 0>
473 template<
class Tuple,
class T>
476 template<
class... Args,
class T>
479 typedef typename std::tuple<Args..., T> type;
488 template<
class Tuple,
class T>
491 template<
class... Args,
class T>
494 typedef typename std::tuple<T, Args...> type;
510 template <
class,
class>
class F,
512 class Seed=std::tuple<>,
513 int N=std::tuple_size<Tuple>::value>
517 typedef typename std::tuple_element<N-1, Tuple>
::type Value;
520 typedef typename F<Accumulated, Value>::type
type;
534 template <
class,
class>
class F,
552 template<
class Head,
class Tail>
567 template<
class Tuple>
Finding the index of a certain type in a std::tuple.
Definition: tupleutility.hh:416
decltype(auto) apply(F &&f, ArgTuple &&args)
Apply function with arguments given as tuple.
Definition: apply.hh:46
constexpr void forEach(Range &&range, F &&f)
Range based for loop.
Definition: hybridutilities.hh:267
auto transformTuple(Tuple &&orig, Args &&... args) -> decltype(genericTransformTuple(orig, makeTransformTupleFunctor< TypeEvaluator >(args...)))
Definition: tupleutility.hh:290
Seed type
Result of the reduce operation.
Definition: tupleutility.hh:540
ReduceTuple< JoinTuples, Tuple >::type type
Result of the flatten operation.
Definition: tupleutility.hh:571
F< Accumulated, Value >::type type
Result of the reduce operation.
Definition: tupleutility.hh:520
ReduceTuple< PushBackTuple, Tail, Head >::type type
Result of the join operation.
Definition: tupleutility.hh:556
auto genericTransformTuple(Tuple &&t, Functor &&f) -> decltype(genericTransformTupleBackend(t, f))
Definition: tupleutility.hh:184
decltype(auto) applyPartial(F &&f, ArgTuple &&args, std::integer_sequence< I, i... >)
Apply function with arguments from a given tuple.
Definition: tupleutility.hh:40
make_index_sequence< typename Dune::SizeOf< T... >{}> index_sequence_for
Create index_sequence from 0 to sizeof...(T)-1.
Definition: utility.hh:38
Dune namespace.
Definition: alignedallocator.hh:14
TypeEvaluator to turn a type T into a pointer to T
Definition: tupleutility.hh:318
TypeEvaluator to turn a type T into a reference to T
Definition: tupleutility.hh:303
Type for reverse element access.
Definition: tupleutility.hh:344
Reverse element access.
Definition: tupleutility.hh:357
Find the first occurrence of a type in a std::tuple.
Definition: tupleutility.hh:465
Flatten a std::tuple of std::tuple's.
Definition: tupleutility.hh:569
Helper template to clone the type definition of a std::tuple with the storage types replaced by a use...
Definition: tupleutility.hh:114
The actual predicate.
Definition: tupleutility.hh:446
Generator for predicates accepting one particular type.
Definition: tupleutility.hh:443
Join two std::tuple's.
Definition: tupleutility.hh:554
A helper template that initializes a std::tuple consisting of pointers to nullptr.
Definition: tupleutility.hh:77
Deletes all objects pointed to in a std::tuple of pointers.
Definition: tupleutility.hh:378
Helper template to append a type to a std::tuple.
Definition: tupleutility.hh:474
Helper template to prepend a type to a std::tuple.
Definition: tupleutility.hh:489
Apply reduce with meta binary function to template.
Definition: tupleutility.hh:515
template mapping a type to std::false_type
Definition: type_traits.hh:79