3#ifndef DUNE_FUNCTIONS_COMMON_UTILITY_HH
4#define DUNE_FUNCTIONS_COMMON_UTILITY_HH
10#include <dune/common/overloadset.hh>
11#include <dune/common/indices.hh>
13#include <dune/functions/common/functionconcepts.hh>
20template<
class F,
class size_type, size_type firstValue,
class... Args>
21auto forwardAsStaticInteger(std::integer_sequence<size_type, firstValue> values,
const size_type& i, F&& f, Args&&... args)
22 ->decltype(f(std::integral_constant<size_type, firstValue>(), std::forward<Args>(args)...))
24 return f(std::integral_constant<size_type, firstValue>(), std::forward<Args>(args)...);
27template<
class F,
class size_type, size_type firstValue, size_type secondValue, size_type... otherValues,
class... Args>
28auto forwardAsStaticInteger(std::integer_sequence<size_type, firstValue, secondValue, otherValues...> values,
const size_type i, F&& f, Args&&... args)
29 ->decltype(f(std::integral_constant<size_type, firstValue>(), std::forward<Args>(args)...))
32 return f(std::integral_constant<size_type, firstValue>(), std::forward<Args>(args)...);
33 return forwardAsStaticInteger(std::integer_sequence<size_type, secondValue, otherValues...>(), i, std::forward<F>(f), std::forward<Args>(args)...);
59template<std::size_t end,
class F,
class size_type,
class... Args>
63 return forwardAsStaticInteger(std::make_index_sequence<end>{}, i, std::forward<F>(f), std::forward<Args>(args)...);
70 template<
template<
class...>
class T,
class List>
71 struct ExpandTupleHelper
74 template<
template<
class...>
class T,
template<
class...>
class ListType,
class... Args>
75 struct ExpandTupleHelper<T, ListType<Args...>>
77 using Type = T<Args...>;
93template<
template<
class...>
class T,
class ArgTuple>
94using ExpandTuple =
typename Imp::ExpandTupleHelper<T, ArgTuple>::Type;
100 template<
template<
class...>
class T,
class... Tuple>
101 struct TransformTupleHelper
104 template<
template<
class...>
class T,
class... Args1>
105 struct TransformTupleHelper<T, typename
std::tuple<Args1...>>
107 using Type = std::tuple<T<Args1>...>;
110 template<
template<
class...>
class T,
class... Args1,
class... Args2>
111 struct TransformTupleHelper<T, typename
std::tuple<Args1...>, typename std::tuple<Args2...>>
113 using Type = std::tuple<T<Args1, Args2>...>;
130template<
template<
class...>
class F,
class... Tuples>
137 template<
class F,
class... T, std::size_t... k>
138 auto transformTupleHelper(F&& f,
const std::tuple<T...>& tuple, std::index_sequence<k...>)
139 ->
decltype(std::make_tuple(f(std::get<k>(tuple))...))
141 return std::make_tuple(f(std::get<k>(tuple))...);
144 template<
class F,
class... T1,
class...T2, std::size_t... k>
145 auto transformTupleHelper(F&& f,
const std::tuple<T1...>& tuple1,
const std::tuple<T2...>& tuple2, std::index_sequence<k...>)
146 ->
decltype(std::make_tuple(f(std::get<k>(tuple1), std::get<k>(tuple2))...))
148 return std::make_tuple(f(std::get<k>(tuple1), std::get<k>(tuple2))...);
164template<
class F,
class... T>
166 ->
decltype(Imp::transformTupleHelper(std::forward<F>(f), tuple, std::index_sequence_for<T...>{}))
168 return Imp::transformTupleHelper(std::forward<F>(f), tuple, std::index_sequence_for<T...>{});
184template<
class F,
class... T1,
class... T2>
185auto transformTuple(F&& f,
const std::tuple<T1...>& tuple1,
const std::tuple<T2...>& tuple2)
186 ->
decltype(Imp::transformTupleHelper(std::forward<F>(f), tuple1, tuple2, std::index_sequence_for<T1...>{}))
188 return Imp::transformTupleHelper(std::forward<F>(f), tuple1, tuple2, std::index_sequence_for<T1...>{});
195 template<
class IntegerSequence>
196 struct IntegerSequenceTupleHelper
199 template<
class I, I... k>
200 struct IntegerSequenceTupleHelper<
std::integer_sequence<I, k...>>
202 using Type = std::tuple<std::integral_constant<I, k>...>;
210template<
class IntegerSequence>
211using IntegerSequenceTuple=
typename Imp::IntegerSequenceTupleHelper<IntegerSequence>::Type;
223 using type =
typename std::tuple_element<
sizeof...(T)-1, std::tuple<T...>>::type;
230template<
class T,
class I>
233template<
class... T, std::size_t... I>
234struct RotateHelper<
std::tuple<T...>, std::index_sequence<I...> >
236 using type =
typename std::tuple<
typename LastType<T...>::type,
typename std::tuple_element<I,std::tuple<T...>>::type...>;
252 using type =
typename Imp::RotateHelper<std::tuple<T...>, std::make_index_sequence<
sizeof...(T)-1>>::type;
278template<
class Expression>
281 return [f](
auto&&... args){
306 return [check](
auto&&... args){
308 [](std::true_type) {
return std::false_type{};},
309 [](std::false_type) {
return std::true_type{};},
310 [](
bool v) {
return not v;});
311 return negate(check(std::forward<
decltype(args)>(args)...));
320 template <
typename T>
321 struct ForwardCaptureWrapper;
323 template <
typename T>
324 struct ForwardCaptureWrapper
326 template <
typename TT>
327 ForwardCaptureWrapper(TT&& t) : t_{
std::forward<TT>(t)} {}
329 auto forward()
const {
return std::move(t_); }
334 template <
typename T>
335 struct ForwardCaptureWrapper<T&>
337 ForwardCaptureWrapper(T& t) : t_{t} {}
339 T& forward()
const {
return t_; };
344 template <
typename T>
345 struct ForwardCaptureWrapper<const T&>
347 ForwardCaptureWrapper(
const T& t) : t_{t} {}
349 const T& forward()
const {
return t_; };
372auto forwardCapture(T&& t)
374 return Impl::ForwardCaptureWrapper<T>(std::forward<T>(t));
constexpr index_constant< 0 > _0
Compile time index with value 0.
Definition: indices.hh:51
auto overload(F &&... f)
Create an overload set.
Definition: overloadset.hh:59
auto transformTuple(Tuple &&orig, Args &&... args) -> decltype(genericTransformTuple(orig, makeTransformTupleFunctor< TypeEvaluator >(args...)))
Definition: tupleutility.hh:290
typename Imp::ExpandTupleHelper< T, ArgTuple >::Type ExpandTuple
Expand tuple arguments as template arguments.
Definition: utility.hh:94
typename Imp::TransformTupleHelper< F, Tuples... >::Type TransformTuple
Transform tuple types argument using type-functor.
Definition: utility.hh:131
static constexpr auto isCallable()
Check if f is callable with given argument list.
Definition: functionconcepts.hh:47
auto callableCheck(Expression f)
Create a predicate for checking validity of expressions.
Definition: utility.hh:279
auto forwardAsStaticIndex(const size_type &i, F &&f, Args &&... args) -> decltype(f(Dune::Indices::_0, std::forward< Args >(args)...))
Transform dynamic index to static index_constant.
Definition: utility.hh:60
auto negatePredicate(Check check)
Negate given predicate.
Definition: utility.hh:304
Dune namespace.
Definition: alignedallocator.hh:11
Get last entry of type list.
Definition: utility.hh:222
Rotate type list by one, such that last entry is moved to first position.
Definition: utility.hh:251