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>
28 struct TupleAccessTraits
30 typedef typename std::add_const<T>::type& ConstType;
31 typedef T& NonConstType;
32 typedef const typename std::remove_const<T>::type& ParameterType;
36 struct TupleAccessTraits<T*>
38 typedef typename std::add_const<T>::type* ConstType;
39 typedef T* NonConstType;
40 typedef T* ParameterType;
44 struct TupleAccessTraits<T&>
47 typedef T& NonConstType;
48 typedef T& ParameterType;
61 template<
class... Args>
64 typedef std::tuple<Args...> ResultType;
65 static ResultType apply()
67 return ResultType(
static_cast<Args
>(
nullptr)...);
95 template<
template <
class>
class TE,
class T>
98 template<
template <
class>
class TE,
class... Args>
101 typedef std::tuple<typename TE<Args>::Type...> Type;
105 template<
class Tuple,
class Functor, std::size_t... I>
107 -> std::tuple<decltype(f(std::get<I>(t)))...>
109 return std::tuple<decltype(f(std::get<I>(t)))...>(f(std::get<I>(t))...);
112 template<
class... Args,
class Functor>
113 auto genericTransformTupleBackend(std::tuple<Args...>& t, Functor& f) ->
114 decltype(genericTransformTupleBackendImpl(t, f,Std::index_sequence_for<Args...>{}))
116 return genericTransformTupleBackendImpl(t, f,Std::index_sequence_for<Args...>{});
119 template<
class... Args,
class Functor>
120 auto genericTransformTupleBackend(
const std::tuple<Args...>& t, Functor& f) ->
121 decltype(genericTransformTupleBackendImpl(t, f, Std::index_sequence_for<Args...>{}))
123 return genericTransformTupleBackendImpl(t, f, Std::index_sequence_for<Args...>{});
165 template<
class Tuple,
class Functor>
167 decltype(genericTransformTupleBackend(t, f))
169 return genericTransformTupleBackend(t, f);
204 template<
template<
class>
class TE,
class... Args>
207 mutable std::tuple<Args&...> tup;
209 template<
class T, std::size_t... I>
211 decltype(TE<T>::apply(t,std::get<I>(tup)...))
const
213 return TE<T>::apply(t,std::get<I>(tup)...);
218 struct TypeEvaluator :
public TE<T>
226 inline auto operator()(T&& t) ->
227 decltype(this->apply(t,Std::index_sequence_for<Args...>{}))
const
229 return apply(t,Std::index_sequence_for<Args...>{});
233 template<
template<
class>
class TE,
class... Args>
271 template<
template<
class>
class TypeEvaluator,
class Tuple,
class... Args>
287 static Type apply(T& t)
301 typedef typename std::remove_reference<T>::type* Type;
302 static Type apply(T& t)
312 typedef typename std::remove_reference<T>::type* Type;
313 static Type apply(T& t)
362 template<
class Tuple>
374 template<
class Functor>
377 Hybrid::forEach(Std::make_index_sequence<std::tuple_size<Tuple>::value>{},
378 [&](
auto i){f.visit(std::get<i>(t_));});
397 template<
class Tuple1,
class Tuple2>
411 template<
class Functor>
414 Hybrid::forEach(Std::make_index_sequence<std::tuple_size<Tuple1>::value>{},
415 [&](
auto i){f.visit(std::get<i>(t1_), std::get<i>(t2_));});
427 template<
int N,
class Tuple>
430 typedef typename std::tuple_element<std::tuple_size<Tuple>::value - N - 1, Tuple>::type Type;
443 template<
typename Tuple>
444 static typename TupleAccessTraits<typename AtType<N, Tuple>::Type>::NonConstType
447 return std::get<std::tuple_size<Tuple>::value - N - 1>(t);
450 template<
typename Tuple>
451 static typename TupleAccessTraits<typename AtType<N, Tuple>::Type>::ConstType
454 return std::get<std::tuple_size<Tuple>::value - N - 1>(t);
461 template<
class Tuple>
464 template<
typename... Ts>
465 static void apply(std::tuple<Ts...>& t)
494 template<
class Tuple,
template<
class>
class Predicate, std::size_t start = 0,
495 std::size_t size = std::tuple_size<Tuple>::value>
497 public std::conditional<Predicate<typename std::tuple_element<start,
498 Tuple>::type>::value,
499 std::integral_constant<std::size_t, start>,
500 FirstPredicateIndex<Tuple, Predicate, start+1> >::type
502 static_assert(std::tuple_size<Tuple>::value == size,
"The \"size\" "
503 "template parameter of FirstPredicateIndex is an "
504 "implementation detail and should never be set "
509 template<
class Tuple,
template<
class>
class Predicate, std::size_t size>
513 "types matches the predicate!");
547 template<
class Tuple,
class T, std::
size_t start = 0>
558 template<
class Tuple,
class T>
561 template<
class... Args,
class T>
564 typedef typename std::tuple<Args..., T> type;
573 template<
class Tuple,
class T>
576 template<
class... Args,
class T>
579 typedef typename std::tuple<T, Args...> type;
595 template <
class,
class>
class F,
597 class Seed=std::tuple<>,
598 int N=std::tuple_size<Tuple>::value>
602 typedef typename std::tuple_element<N-1, Tuple>
::type Value;
605 typedef typename F<Accumulated, Value>::type
type;
619 template <
class,
class>
class F,
637 template<
class Head,
class Tail>
652 template<
class Tuple>
Finding the index of a certain type in a std::tuple.
Definition: tupleutility.hh:501
Extension of ForEachValue to two std::tuple's.
Definition: tupleutility.hh:399
Helper template which implements iteration over all storage elements in a std::tuple.
Definition: tupleutility.hh:364
an implementation of std::integer_sequence as introduced in C++14
Definition: utility.hh:37
constexpr void forEach(Range &&range, F &&f)
Range based for loop.
Definition: hybridutilities.hh:314
ForEachValuePair(Tuple1 &t1, Tuple2 &t2)
Definition: tupleutility.hh:404
auto transformTuple(Tuple &&orig, Args &&... args) -> decltype(genericTransformTuple(orig, makeTransformTupleFunctor< TypeEvaluator >(args...)))
Definition: tupleutility.hh:272
Seed type
Result of the reduce operation.
Definition: tupleutility.hh:625
void apply(Functor &f)
Definition: tupleutility.hh:412
ReduceTuple< JoinTuples, Tuple >::type type
Result of the flatten operation.
Definition: tupleutility.hh:656
F< Accumulated, Value >::type type
Result of the reduce operation.
Definition: tupleutility.hh:605
ForEachValue(Tuple &t)
Constructor.
Definition: tupleutility.hh:368
ReduceTuple< PushBackTuple, Tail, Head >::type type
Result of the join operation.
Definition: tupleutility.hh:641
void apply(Functor &f) const
Applies a function object to each storage element of the std::tuple.
Definition: tupleutility.hh:375
auto genericTransformTuple(Tuple &&t, Functor &&f) -> decltype(genericTransformTupleBackend(t, f))
Definition: tupleutility.hh:166
Dune namespace.
Definition: alignment.hh:11
TypeEvaluator to turn a type T into a pointer to T
Definition: tupleutility.hh:300
TypeEvaluator to turn a type T into a reference to T
Definition: tupleutility.hh:285
Type for reverse element access.
Definition: tupleutility.hh:429
Reverse element access.
Definition: tupleutility.hh:442
Find the first occurrence of a type in a std::tuple.
Definition: tupleutility.hh:550
Flatten a std::tuple of std::tuple's.
Definition: tupleutility.hh:654
Helper template to clone the type definition of a std::tuple with the storage types replaced by a use...
Definition: tupleutility.hh:96
The actual predicate.
Definition: tupleutility.hh:531
Generator for predicates accepting one particular type.
Definition: tupleutility.hh:528
Join two std::tuple's.
Definition: tupleutility.hh:639
A helper template that initializes a std::tuple consisting of pointers to nullptr.
Definition: tupleutility.hh:59
Deletes all objects pointed to in a std::tuple of pointers.
Definition: tupleutility.hh:463
Helper template to append a type to a std::tuple.
Definition: tupleutility.hh:559
Helper template to prepend a type to a std::tuple.
Definition: tupleutility.hh:574
Apply reduce with meta binary function to template.
Definition: tupleutility.hh:600
template mapping a type to std::false_type
Definition: type_traits.hh:63