4#ifndef DUNE_TUPLE_UTILITY_HH
5#define DUNE_TUPLE_UTILITY_HH
12#include <dune/common/hybridutilities.hh>
13#include <dune/common/std/type_traits.hh>
14#include <dune/common/std/utility.hh>
29 struct TupleAccessTraits
31 typedef typename std::add_const<T>::type& ConstType;
32 typedef T& NonConstType;
33 typedef const typename std::remove_const<T>::type& ParameterType;
37 struct TupleAccessTraits<T*>
39 typedef typename std::add_const<T>::type* ConstType;
40 typedef T* NonConstType;
41 typedef T* ParameterType;
45 struct TupleAccessTraits<T&>
48 typedef T& NonConstType;
49 typedef T& ParameterType;
62 template<
class... Args>
65 typedef std::tuple<Args...> ResultType;
66 static ResultType
apply()
68 return ResultType(
static_cast<Args
>(
nullptr)...);
96 template<
template <
class>
class TE,
class T>
99 template<
template <
class>
class TE,
class... Args>
102 typedef std::tuple<typename TE<Args>::Type...> Type;
106 template<
class Tuple,
class Functor, std::size_t... I>
107 inline auto genericTransformTupleBackendImpl(Tuple& t, Functor& f,
const Std::index_sequence<I...>& )
108 -> std::tuple<decltype(f(std::get<I>(t)))...>
110 return std::tuple<decltype(f(std::get<I>(t)))...>(f(std::get<I>(t))...);
113 template<
class... Args,
class Functor>
114 auto genericTransformTupleBackend(std::tuple<Args...>& t, Functor& f) ->
115 decltype(genericTransformTupleBackendImpl(t, f,Std::index_sequence_for<Args...>{}))
117 return genericTransformTupleBackendImpl(t, f,Std::index_sequence_for<Args...>{});
120 template<
class... Args,
class Functor>
121 auto genericTransformTupleBackend(
const std::tuple<Args...>& t, Functor& f) ->
122 decltype(genericTransformTupleBackendImpl(t, f, Std::index_sequence_for<Args...>{}))
124 return genericTransformTupleBackendImpl(t, f, Std::index_sequence_for<Args...>{});
166 template<
class Tuple,
class Functor>
168 decltype(genericTransformTupleBackend(t, f))
170 return genericTransformTupleBackend(t, f);
205 template<
template<
class>
class TE,
class... Args>
208 mutable std::tuple<Args&...> tup;
210 template<
class T, std::size_t... I>
211 inline auto apply(T&& t,
const Std::index_sequence<I...>& ) ->
219 struct TypeEvaluator :
public TE<T>
227 inline auto operator()(T&& t) ->
234 template<
template<
class>
class TE,
class... Args>
272 template<
template<
class>
class TypeEvaluator,
class Tuple,
class... Args>
288 static Type apply(T& t)
302 typedef typename std::remove_reference<T>::type* Type;
303 static Type apply(T& t)
313 typedef typename std::remove_reference<T>::type* Type;
314 static Type
apply(T& t)
320 template<
class Tuple>
323 ForEachValue(Tuple& t) :
327 template<
class Functor>
328 void apply(Functor& f)
const
330 Hybrid::forEach(Std::make_index_sequence<std::tuple_size<Tuple>::value>{},
331 [&](
auto i){f.visit(std::get<i>(t_));});
337 template<
class Tuple1,
class Tuple2>
340 ForEachValuePair(Tuple1& t1, Tuple2& t2) :
345 template<
class Functor>
346 void apply(Functor& f)
348 Hybrid::forEach(Std::make_index_sequence<std::tuple_size<Tuple1>::value>{},
349 [&](
auto i){f.visit(std::get<i>(t1_), std::get<i>(t2_));});
361 template<
int N,
class Tuple>
364 typedef typename std::tuple_element<std::tuple_size<Tuple>::value - N - 1, Tuple>::type Type;
377 template<
typename Tuple>
378 static typename TupleAccessTraits<typename AtType<N, Tuple>::Type>::NonConstType
381 return std::get<std::tuple_size<Tuple>::value - N - 1>(t);
384 template<
typename Tuple>
385 static typename TupleAccessTraits<typename AtType<N, Tuple>::Type>::ConstType
388 return std::get<std::tuple_size<Tuple>::value - N - 1>(t);
395 template<
class Tuple>
398 template<
typename... Ts>
399 static void apply(std::tuple<Ts...>& t)
428 template<
class Tuple,
template<
class>
class Predicate, std::size_t start = 0,
429 std::size_t size = std::tuple_size<Tuple>::value>
431 public std::conditional<Predicate<typename std::tuple_element<start,
432 Tuple>::type>::value,
433 std::integral_constant<std::size_t, start>,
434 FirstPredicateIndex<Tuple, Predicate, start+1> >::type
436 static_assert(std::tuple_size<Tuple>::value == size,
"The \"size\" "
437 "template parameter of FirstPredicateIndex is an "
438 "implementation detail and should never be set "
443 template<
class Tuple,
template<
class>
class Predicate, std::size_t size>
447 "types matches the predicate!");
481 template<
class Tuple,
class T, std::
size_t start = 0>
492 template<
class Tuple,
class T>
495 template<
class... Args,
class T>
498 typedef typename std::tuple<Args..., T> type;
507 template<
class Tuple,
class T>
510 template<
class... Args,
class T>
513 typedef typename std::tuple<T, Args...> type;
529 template <
class,
class>
class F,
531 class Seed=std::tuple<>,
532 int N=std::tuple_size<Tuple>::value>
536 typedef typename std::tuple_element<N-1, Tuple>
::type Value;
539 typedef typename F<Accumulated, Value>::type
type;
553 template <
class,
class>
class F,
571 template<
class Head,
class Tail>
586 template<
class Tuple>
Finding the index of a certain type in a std::tuple.
Definition: tupleutility.hh:435
Definition of the DUNE_DEPRECATED macro for the case that config.h is not available.
decltype(auto) apply(F &&f, ArgTuple &&args)
Apply function with arguments given as tuple.
Definition: apply.hh:58
#define DUNE_DEPRECATED_MSG(text)
Mark some entity as deprecated.
Definition: deprecated.hh:169
constexpr void forEach(Range &&range, F &&f)
Range based for loop.
Definition: hybridutilities.hh:308
auto transformTuple(Tuple &&orig, Args &&... args) -> decltype(genericTransformTuple(orig, makeTransformTupleFunctor< TypeEvaluator >(args...)))
Definition: tupleutility.hh:273
Seed type
Result of the reduce operation.
Definition: tupleutility.hh:559
ReduceTuple< JoinTuples, Tuple >::type type
Result of the flatten operation.
Definition: tupleutility.hh:590
F< Accumulated, Value >::type type
Result of the reduce operation.
Definition: tupleutility.hh:539
ReduceTuple< PushBackTuple, Tail, Head >::type type
Result of the join operation.
Definition: tupleutility.hh:575
auto genericTransformTuple(Tuple &&t, Functor &&f) -> decltype(genericTransformTupleBackend(t, f))
Definition: tupleutility.hh:167
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:10
TypeEvaluator to turn a type T into a pointer to T
Definition: tupleutility.hh:301
TypeEvaluator to turn a type T into a reference to T
Definition: tupleutility.hh:286
Type for reverse element access.
Definition: tupleutility.hh:363
Reverse element access.
Definition: tupleutility.hh:376
Find the first occurrence of a type in a std::tuple.
Definition: tupleutility.hh:484
Flatten a std::tuple of std::tuple's.
Definition: tupleutility.hh:588
Helper template to clone the type definition of a std::tuple with the storage types replaced by a use...
Definition: tupleutility.hh:97
The actual predicate.
Definition: tupleutility.hh:465
Generator for predicates accepting one particular type.
Definition: tupleutility.hh:462
Join two std::tuple's.
Definition: tupleutility.hh:573
A helper template that initializes a std::tuple consisting of pointers to nullptr.
Definition: tupleutility.hh:60
Deletes all objects pointed to in a std::tuple of pointers.
Definition: tupleutility.hh:397
Helper template to append a type to a std::tuple.
Definition: tupleutility.hh:493
Helper template to prepend a type to a std::tuple.
Definition: tupleutility.hh:508
Apply reduce with meta binary function to template.
Definition: tupleutility.hh:534
template mapping a type to std::false_type
Definition: type_traits.hh:79