dune-functions  2.6-dev
Modules | Classes | Typedefs | Functions
Utility

Various helper classes and functions. More...

Collaboration diagram for Utility:

Modules

 Utilities for type-erasure
 Helper classes for implementing type-erased interfaces.
 

Classes

class  Dune::Functions::PolymorphicType< Interface >
 Base class with polymorphic type boiler plate code. More...
 
class  Dune::Functions::PolymorphicSmallObject< Base, bufferSize >
 A wrapper providing small object optimization with polymorphic types. More...
 
class  Dune::Functions::ReservedDeque< T, n >
 A Vector class with statically reserved memory. More...
 
struct  Dune::Functions::UniformNodeVisitor< SimpleNodeVisitorImp, leafOnly >
 Mixin for visitors that should apply the same action on all nodes. More...
 
class  Dune::Functions::TreeData< T, ND, LO >
 Container allowing to attach data to each node of a tree. More...
 
struct  Dune::Functions::HasStaticSize< T >
 Check if type is a statically sized container. More...
 
struct  Dune::Functions::StaticSize< T >
 Obtain size of statically sized container. More...
 
struct  Dune::Functions::LastType< T >
 Get last entry of type list. More...
 
struct  Dune::Functions::RotateTuple< T >
 Rotate type list by one, such that last entry is moved to first position. More...
 

Typedefs

template<class T , class... Args>
using Dune::Functions::enableIfConstructible = typename std::enable_if< std::is_constructible< T, Args... >::value, int >::type
 Helper to constrain forwarding constructors. More...
 
template<template< class... > class T, class ArgTuple >
using Dune::Functions::ExpandTuple = typename Imp::ExpandTupleHelper< T, ArgTuple >::Type
 Expand tuple arguments as template arguments. More...
 
template<template< class... > class F, class... Tuples>
using Dune::Functions::TransformTuple = typename Imp::TransformTupleHelper< F, Tuples... >::Type
 Transform tuple types argument using type-functor. More...
 

Functions

template<class C , class I , class F , typename std::enable_if< Dune::models< Imp::Concept::HasDynamicIndexAccess< I >, C >(), int >::type = 0>
auto Dune::Functions::hybridIndexAccess (C &&c, const I &i, F &&f) -> decltype(f(c[i]))
 Provide operator[] index-access for containers. More...
 
template<class Result , class C , class MultiIndex >
Result Dune::Functions::hybridMultiIndexAccess (C &&c, const MultiIndex &index)
 Provide multi-index access by chaining operator[]. More...
 
template<std::size_t begin_t, std::size_t end_t, class F , class... Args>
void Dune::Functions::staticFindInRange (F &&f, Args &&... args)
 Static find loop. More...
 
template<std::size_t end, class F , class size_type , class... Args>
auto Dune::Functions::forwardAsStaticIndex (const size_type &i, F &&f, Args &&... args) -> decltype(f(Dune::TypeTree::Indices::_0, std::forward< Args >(args)...))
 Transform dynamic index to static index_constant. More...
 
template<class F , class... T>
auto Dune::Functions::transformTuple (F &&f, const std::tuple< T... > &tuple) -> decltype(Imp::transformTupleHelper(std::forward< F >(f), tuple, std::index_sequence_for< T... >
 Transform tuple value using a functor. More...
 
template<class F , class... T1, class... T2>
auto Dune::Functions::transformTuple (F &&f, const std::tuple< T1... > &tuple1, const std::tuple< T2... > &tuple2) -> decltype(Imp::transformTupleHelper(std::forward< F >(f), tuple1, tuple2, std::index_sequence_for< T1... >
 Transform tuple value using a binary functor. More...
 
template<class F , class ArgTuple , class I , I... i>
decltype(auto) Dune::Functions::applyPartial (F &&f, ArgTuple &&args, std::integer_sequence< I, i... > indices)
 Apply function with arguments from a given tuple. More...
 

Detailed Description

Various helper classes and functions.

Typedef Documentation

◆ enableIfConstructible

template<class T , class... Args>
using Dune::Functions::enableIfConstructible = typedef typename std::enable_if< std::is_constructible<T, Args...>::value, int>::type

Helper to constrain forwarding constructors.

Helper typedef to remove constructor with forwarding reference from overload set for type is not constructible from argument list. This is useful to avoid failng forwarding constructors for base classes or members.

◆ ExpandTuple

template<template< class... > class T, class ArgTuple >
using Dune::Functions::ExpandTuple = typedef typename Imp::ExpandTupleHelper<T, ArgTuple>::Type

Expand tuple arguments as template arguments.

This template alias refers to T<Args...> if ArgTuple is a std::tuple<Args...>.

Template Parameters
TA variadic template
ArgTupleA tuple of types

◆ TransformTuple

template<template< class... > class F, class... Tuples>
using Dune::Functions::TransformTuple = typedef typename Imp::TransformTupleHelper<F, Tuples...>::Type

Transform tuple types argument using type-functor.

This is a template alias for a tuple whose i-th type is given by F<T1i,...,TMi> where T1i,...,TMi are the i-th types of the 1,...,M-th tuple of the given tuple list Tuples. Currently only M=1,2 are supported.

Template Parameters
FA template alias mapping 1,...,sizeof...(ArgTuple) types to a new one
TuplesA list of tuples

Function Documentation

◆ applyPartial()

template<class F , class ArgTuple , class I , I... i>
decltype(auto) Dune::Functions::applyPartial ( F &&  f,
ArgTuple &&  args,
std::integer_sequence< I, i... >  indices 
)

Apply function with arguments from a given tuple.

Parameters
fA callable object
argsTuple containing the arguments
indicesIndices to arguments in tuple as std::integer_sequence

This will call the function with arguments generated by unpacking those entries of the tuple that show up given integer_sequence.

◆ forwardAsStaticIndex()

template<std::size_t end, class F , class size_type , class... Args>
auto Dune::Functions::forwardAsStaticIndex ( const size_type &  i,
F &&  f,
Args &&...  args 
) -> decltype(f(Dune::TypeTree::Indices::_0, std::forward<Args>(args)...))

Transform dynamic index to static index_constant.

This will call the given function with index_constant where i is the dynamically provided index.

To achieve this the conditon i==ii is checked subsequently for al static indices ii in the range 0,...,(end-1). In order to be able to compile this we require for all ii in this range that f(index_constant<ii>()) is well-formed and that the result type of it can be converted to the result type of f(index_constant<0>()). If i is not in this range, the returned value is f(index_constant<n-1>())

Parameters
iDynamic index
fFunction to call (e.g., a generic lambda)
argsAdditional arguments for f
Returns
f(index_constant<i>(), args...)

◆ hybridIndexAccess()

template<class C , class I , class F , typename std::enable_if< Dune::models< Imp::Concept::HasDynamicIndexAccess< I >, C >(), int >::type = 0>
auto Dune::Functions::hybridIndexAccess ( C &&  c,
const I &  i,
F &&  f 
) -> decltype(f(c[i]))

Provide operator[] index-access for containers.

This is the overload for types providing a operator[] for dynamic std::size_t arguments.

Parameters
cContainer to access
iThe index to use for accessing the container
fA functor to call with the result of operator[]

◆ hybridMultiIndexAccess()

template<class Result , class C , class MultiIndex >
Result Dune::Functions::hybridMultiIndexAccess ( C &&  c,
const MultiIndex &  index 
)

Provide multi-index access by chaining operator[].

This provides access to a nested container by given multi-index. Internally this is resolved by recusive operator[]-calls with static or dynamic indices. Because this recursion must be terminated using a compile-time criterion, the result type must explicitly be provided. The recursion will terminate once the result can be converted to this result type.

Template Parameters
ResultType of result
Parameters
cContainer to access
indexMulti-index

◆ staticFindInRange()

template<std::size_t begin_t, std::size_t end_t, class F , class... Args>
void Dune::Functions::staticFindInRange ( F &&  f,
Args &&...  args 
)

Static find loop.

Run static for-loop from 'begin' to 'end-1' with functor. The functor is called with TypeTree::index_constant<i> as first argument. All other arguments of this method are forwarded to the functor. If the functor returns true the loop is terminated.

Todo:
Should this be just the StaticForLoop?

◆ transformTuple() [1/2]

template<class F , class... T>
auto Dune::Functions::transformTuple ( F &&  f,
const std::tuple< T... > &  tuple 
) -> decltype(Imp::transformTupleHelper(std::forward<F>(f), tuple, std::index_sequence_for<T...>

Transform tuple value using a functor.

This will apply the given functor to all values in given tuple and return the results in a new tuple.

Parameters
FA functor defined for all tuple entries
tupleThe tuple to transform

◆ transformTuple() [2/2]

template<class F , class... T1, class... T2>
auto Dune::Functions::transformTuple ( F &&  f,
const std::tuple< T1... > &  tuple1,
const std::tuple< T2... > &  tuple2 
) -> decltype(Imp::transformTupleHelper(std::forward<F>(f), tuple1, tuple2, std::index_sequence_for<T1...>

Transform tuple value using a binary functor.

This will apply the given functor to the each corresponding pair of values in the given tuples and return the results in a new tuple.

Parameters
FA functor defined for all tuple entries
tuple1The tuple containing values for the first parameter
tuple2The tuple containing values for the second parameter