7#ifndef DUNE_FUNCTIONS_COMMON_UTILITY_HH
8#define DUNE_FUNCTIONS_COMMON_UTILITY_HH
14#include <dune/common/overloadset.hh>
15#include <dune/common/indices.hh>
17#include <dune/functions/common/functionconcepts.hh>
24template<
class F,
class size_type, size_type firstValue,
class... Args>
25auto forwardAsStaticInteger(std::integer_sequence<size_type, firstValue> values,
const size_type& i, F&& f, Args&&... args)
26 ->decltype(f(std::integral_constant<size_type, firstValue>(), std::forward<Args>(args)...))
28 return f(std::integral_constant<size_type, firstValue>(), std::forward<Args>(args)...);
31template<
class F,
class size_type, size_type firstValue, size_type secondValue, size_type... otherValues,
class... Args>
32auto forwardAsStaticInteger(std::integer_sequence<size_type, firstValue, secondValue, otherValues...> values,
const size_type i, F&& f, Args&&... args)
33 ->decltype(f(std::integral_constant<size_type, firstValue>(), std::forward<Args>(args)...))
36 return f(std::integral_constant<size_type, firstValue>(), std::forward<Args>(args)...);
37 return forwardAsStaticInteger(std::integer_sequence<size_type, secondValue, otherValues...>(), i, std::forward<F>(f), std::forward<Args>(args)...);
63template<std::size_t end,
class F,
class size_type,
class... Args>
67 return forwardAsStaticInteger(std::make_index_sequence<end>{}, i, std::forward<F>(f), std::forward<Args>(args)...);
74 template<
template<
class...>
class T,
class List>
75 struct ExpandTupleHelper
78 template<
template<
class...>
class T,
template<
class...>
class ListType,
class... Args>
79 struct ExpandTupleHelper<T, ListType<Args...>>
81 using Type = T<Args...>;
97template<
template<
class...>
class T,
class ArgTuple>
98using ExpandTuple =
typename Imp::ExpandTupleHelper<T, ArgTuple>::Type;
104 template<
template<
class...>
class T,
class... Tuple>
105 struct TransformTupleHelper
108 template<
template<
class...>
class T,
class... Args1>
109 struct TransformTupleHelper<T, typename
std::tuple<Args1...>>
111 using Type = std::tuple<T<Args1>...>;
114 template<
template<
class...>
class T,
class... Args1,
class... Args2>
115 struct TransformTupleHelper<T, typename
std::tuple<Args1...>, typename std::tuple<Args2...>>
117 using Type = std::tuple<T<Args1, Args2>...>;
134template<
template<
class...>
class F,
class... Tuples>
141 template<
class F,
class... T, std::size_t... k>
142 auto transformTupleHelper(F&& f,
const std::tuple<T...>& tuple, std::index_sequence<k...>)
143 ->
decltype(std::make_tuple(f(std::get<k>(tuple))...))
145 return std::make_tuple(f(std::get<k>(tuple))...);
148 template<
class F,
class... T1,
class...T2, std::size_t... k>
149 auto transformTupleHelper(F&& f,
const std::tuple<T1...>& tuple1,
const std::tuple<T2...>& tuple2, std::index_sequence<k...>)
150 ->
decltype(std::make_tuple(f(std::get<k>(tuple1), std::get<k>(tuple2))...))
152 return std::make_tuple(f(std::get<k>(tuple1), std::get<k>(tuple2))...);
168template<
class F,
class... T>
170 ->
decltype(Imp::transformTupleHelper(std::forward<F>(f), tuple, std::index_sequence_for<T...>{}))
172 return Imp::transformTupleHelper(std::forward<F>(f), tuple, std::index_sequence_for<T...>{});
188template<
class F,
class... T1,
class... T2>
189auto transformTuple(F&& f,
const std::tuple<T1...>& tuple1,
const std::tuple<T2...>& tuple2)
190 ->
decltype(Imp::transformTupleHelper(std::forward<F>(f), tuple1, tuple2, std::index_sequence_for<T1...>{}))
192 return Imp::transformTupleHelper(std::forward<F>(f), tuple1, tuple2, std::index_sequence_for<T1...>{});
199 template<
class IntegerSequence>
200 struct IntegerSequenceTupleHelper
203 template<
class I, I... k>
204 struct IntegerSequenceTupleHelper<
std::integer_sequence<I, k...>>
206 using Type = std::tuple<std::integral_constant<I, k>...>;
214template<
class IntegerSequence>
215using IntegerSequenceTuple=
typename Imp::IntegerSequenceTupleHelper<IntegerSequence>::Type;
227 using type = std::tuple_element_t<
sizeof...(T)-1, std::tuple<T...>>;
234template<
class T,
class I>
237template<
class... T, std::size_t... I>
238struct RotateHelper<
std::tuple<T...>, std::index_sequence<I...> >
240 using type =
typename std::tuple<
typename LastType<T...>::type, std::tuple_element_t<I,std::tuple<T...>>...>;
256 using type =
typename Imp::RotateHelper<std::tuple<T...>, std::make_index_sequence<
sizeof...(T)-1>>::type;
282template<
class Expression>
285 return [f](
auto&&... args){
310 return [check](
auto&&... args){
312 [](std::true_type) {
return std::false_type{};},
313 [](std::false_type) {
return std::true_type{};},
314 [](
bool v) {
return not v;});
315 return negate(check(std::forward<
decltype(args)>(args)...));
324 template <
typename T>
325 struct ForwardCaptureWrapper;
327 template <
typename T>
328 struct ForwardCaptureWrapper
330 template <
typename TT>
331 ForwardCaptureWrapper(TT&& t) : t_{
std::forward<TT>(t)} {}
333 auto forward()
const {
return std::move(t_); }
338 template <
typename T>
339 struct ForwardCaptureWrapper<T&>
341 ForwardCaptureWrapper(T& t) : t_{t} {}
343 T& forward()
const {
return t_; };
348 template <
typename T>
349 struct ForwardCaptureWrapper<const T&>
351 ForwardCaptureWrapper(
const T& t) : t_{t} {}
353 const T& forward()
const {
return t_; };
376auto forwardCapture(T&& t)
378 return Impl::ForwardCaptureWrapper<T>(std::forward<T>(t));
constexpr index_constant< 0 > _0
Compile time index with value 0.
Definition: indices.hh:52
auto overload(F &&... f)
Create an overload set.
Definition: overloadset.hh:61
auto transformTuple(Tuple &&orig, Args &&... args) -> decltype(genericTransformTuple(orig, makeTransformTupleFunctor< TypeEvaluator >(args...)))
Definition: tupleutility.hh:292
typename Imp::ExpandTupleHelper< T, ArgTuple >::Type ExpandTuple
Expand tuple arguments as template arguments.
Definition: utility.hh:98
typename Imp::TransformTupleHelper< F, Tuples... >::Type TransformTuple
Transform tuple types argument using type-functor.
Definition: utility.hh:135
static constexpr auto isCallable()
Check if f is callable with given argument list.
Definition: functionconcepts.hh:51
auto callableCheck(Expression f)
Create a predicate for checking validity of expressions.
Definition: utility.hh:283
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:64
auto negatePredicate(Check check)
Negate given predicate.
Definition: utility.hh:308
Dune namespace.
Definition: alignedallocator.hh:13
Get last entry of type list.
Definition: utility.hh:226
Rotate type list by one, such that last entry is moved to first position.
Definition: utility.hh:255