Loading...
Searching...
No Matches
Utility

Various helper classes and functions. More...

Collaboration diagram for Utility:

## Topics

| 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 double-ended queue (deque) class with statically reserved memory. More...
class | Dune::Functions::Experimental::SubDomainIndexSet< HGV >
| An IndexSet for a sub-domain. More...
class | Dune::Functions::Experimental::SubDomainGridView< HGV >
| A GridView for a sub-domain. More...
class | Dune::Functions::Experimental::SubDomain< HGV >
| Class representing a sub-domain of a GridView. More...
struct | Dune::Functions::HasStaticSize< T >
| Check if type is a statically sized container. More...
struct | Dune::Functions::StaticSizeOrZero< T >
| Obtain size of statically sized container, or 0 if dynamic size. 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
| Helper to constrain forwarding constructors.
template<class T>
using | Dune::Functions::StaticSize
| Obtain size of statically sized container as integral_constant, or fail.
template<template< class... > class T, class ArgTuple>
using | Dune::Functions::ExpandTuple = typename Imp::ExpandTupleHelper<T, ArgTuple>::Type
| Expand tuple arguments as template arguments.
template<template< class... > class F, class... Tuples>
using | Dune::Functions::TransformTuple = typename Imp::TransformTupleHelper<F, Tuples...>::Type
| Transform tuple types argument using type-functor.

## Functions

template<class F, class... Args>
static constexpr auto | Dune::Functions::Concept::isCallable ()
| Check if f is callable with given argument list.
template<class F, class... Args>
static constexpr auto | Dune::Functions::Concept::isCallable (F &&, Args &&...)
| Check if f is callable with given argument list.
template<class C, class I, class F, std::enable_if_t< Dune::models< Imp::Concept::HasDynamicIndexAccess< I >, C >(), int > = 0>
auto | Dune::Functions::hybridIndexAccess (C &&c, const I &i, F &&f) -> decltype(f(c[i]))
| Provide operator[] index-access for containers.
template<class C, class I, class F, std::enable_if_t< not Dune::models< Imp::Concept::HasDynamicIndexAccess< I >, C >(), int > = 0>
decltype(auto) | Dune::Functions::hybridIndexAccess (C &&c, const I &i, F &&f)
| Provide operator[] index-access for containers.
template<class Result, class C, class MultiIndex>
Result | Dune::Functions::hybridMultiIndexAccess (C &&c, const MultiIndex &index)
| Provide multi-index access by chaining operator[].
template<class C, class MultiIndex, class IsFinal>
constexpr decltype(auto) | Dune::Functions::resolveDynamicMultiIndex (C &&c, const MultiIndex &multiIndex, const IsFinal &isFinal)
| Provide multi-index access by chaining operator[].
template<class C, class MultiIndex>
constexpr decltype(auto) | Dune::Functions::resolveDynamicMultiIndex (C &&c, const MultiIndex &multiIndex)
| Provide multi-index access by chaining operator[].
template<class C, class MultiIndex>
constexpr decltype(auto) | Dune::Functions::resolveStaticMultiIndex (C &&c, const MultiIndex &multiIndex)
| Provide multi-index access by chaining operator[].
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.
template<class HostGridView>
auto | Dune::Functions::Experimental::elements (const SubDomainGridView< HostGridView > &subDomainGridView)
| ADL findable access to element range for a SubDomainGridView.
template<class HostGridView, unsigned int partitions>
auto | Dune::Functions::Experimental::elements (const SubDomainGridView< HostGridView > &subDomainGridView, Dune::PartitionSet< partitions > partitionSet)
| ADL findable access to element range for a SubDomainGridView.
template<class HostGridView, class Element>
auto | Dune::Functions::Experimental::intersections (const SubDomainGridView< HostGridView > &subDomainGridView, const Element &element)
| ADL findable access to intersection range for an element of a SubDomainGridView.
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::Indices::_0, std::forward< Args >(args)...))
| Transform dynamic index to static index_constant.
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.
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.
template<class Expression>
auto | Dune::Functions::callableCheck (Expression f)
| Create a predicate for checking validity of expressions.
template<class Check>
auto | Dune::Functions::negatePredicate (Check check)
| Negate given predicate.

## Detailed Description

Various helper classes and functions.

## Typedef Documentation

## enableIfConstructible

template<class T, class... Args>

using Dune::Functions::enableIfConstructible

Initial value:
std::enable_if_t<
std::is_constructible_v<T, Args...>, int>

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 failing forwarding constructors for base classes or members.

## ExpandTuple

template<template< class... > class T, class ArgTuple>

using Dune::Functions::ExpandTuple = 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

  T | A variadic template
  ArgTuple | A tuple of types

## StaticSize

template<class T>

using Dune::Functions::StaticSize

Initial value:
std::enable_if_t<HasStaticSize_v<T>,
decltype(Dune::Hybrid::size(std::declval<T>()))>

Obtain size of statically sized container as integral_constant, or fail.

## TransformTuple

template<template< class... > class F, class... Tuples>

using Dune::Functions::TransformTuple = 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

  F | A template alias mapping 1,...,sizeof...(ArgTuple) types to a new one
  Tuples | A list of tuples

## Function Documentation

## callableCheck()

template<class Expression>

auto Dune::Functions::callableCheck | ( | Expression | f | ) |

Create a predicate for checking validity of expressions.

Parameters

  f | A function involving the expression to check.

This returns a function object that allows to check if the expression encoded in f is valid for the given arguments. To be precise it checks if f can be called using the given arguments. This can be used in the following way: To generate a check if the expression x(a,b) is valid for some a and b use:

auto xIsValid = callableCheck([](auto&& a, auto&& b) -> std::void_t<decltype(x(a,b))> {});
if (xIsValid(a,b))
...
Dune::Functions::callableCheck
auto callableCheck(Expression f)
Create a predicate for checking validity of expressions.
Definition utility.hh:287

Notice that the given function f is stored by value.

## elements() [1/2]

template<class HostGridView>

auto Dune::Functions::Experimental::elements | ( | const SubDomainGridView< HostGridView > & | subDomainGridView | ) |

ADL findable access to element range for a SubDomainGridView.

## elements() [2/2]

template<class HostGridView, unsigned int partitions>

auto Dune::Functions::Experimental::elements | ( | const SubDomainGridView< HostGridView > & | subDomainGridView,
|  | Dune::PartitionSet< partitions > | partitionSet )

ADL findable access to element range for a SubDomainGridView.

## 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::Indices::_0, std::forward< Args >(args)...))

Transform dynamic index to static index_constant.

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

To achieve this the condition 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

  i | Dynamic index
  f | Function to call (e.g., a generic lambda)
  args | Additional arguments for f

Returns
  f(index_constant<i>(), args...)

Deprecated
  This will be removed in 2.11. use Dune::Hybrid::switchCases instead.

## hybridIndexAccess() [1/2]

template<class C, class I, class F, std::enable_if_t< not Dune::models< Imp::Concept::HasDynamicIndexAccess< I >, C >(), int > = 0>

decltype(auto) Dune::Functions::hybridIndexAccess | ( | C && | c,
|  | const I & | i,
|  | F && | f )

Provide operator[] index-access for containers.

This is the overload for types providing a operator[] only for static arguments of type std::integral_constant<std::size_t,k>. This does a static linear search until a static index matching the given dynamic index is found. Since the result type will in general be different for different indices the method does not return the result directly but passes it to a given functor.

Parameters

  c | Container to access
  i | The index to use for accessing the container
  f | A functor to call with the result of operator[]

## hybridIndexAccess() [2/2]

template<class C, class I, class F, std::enable_if_t< Dune::models< Imp::Concept::HasDynamicIndexAccess< I >, C >(), int > = 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

  c | Container to access
  i | The index to use for accessing the container
  f | A 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 recursive 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

  Result | Type of result

Parameters

  c | Container to access
  index | Multi-index

## intersections()

template<class HostGridView, class Element>

auto Dune::Functions::Experimental::intersections | ( | const SubDomainGridView< HostGridView > & | subDomainGridView,
|  | const Element & | element )

ADL findable access to intersection range for an element of a SubDomainGridView.

## isCallable() [1/2]

template<class F, class... Args>

constexpr auto Dune::Functions::Concept::isCallable | ( |  | ) |

static constexpr

Check if f is callable with given argument list.

## isCallable() [2/2]

template<class F, class... Args>

constexpr auto Dune::Functions::Concept::isCallable | ( | F && | ,
|  | Args && | ... )

static constexpr

Check if f is callable with given argument list.

## negatePredicate()

template<class Check>

auto Dune::Functions::negatePredicate | ( | Check | check | ) |

Negate given predicate.

Parameters

  check | A predicate function to negate

This returns a function having the same parameters as f, but negating the result. Negation here means that std::true_type is converted to std::false_type are vice verse, while other return values are converted to bool values and then the negated value is returned as bool, too.

Notice that the given function f is stored by value.

## resolveDynamicMultiIndex() [1/2]

template<class C, class MultiIndex>

decltype(auto) Dune::Functions::resolveDynamicMultiIndex | ( | C && | c,
|  | const MultiIndex & | multiIndex )

constexpr

Provide multi-index access by chaining operator[].

This provides access to a nested container by given dynamically sized multi-index. Internally this is resolved by recursive operator[]-calls with static or dynamic indices. Because this recursion must be terminated, a predicate is used to determine if a type is considered final for the multi-index resolution. This version terminates the recursion on values that neither have a static nor a dynamic operator[].

Parameters

  c | Container to access
  multiIndex | Multi-index

## resolveDynamicMultiIndex() [2/2]

template<class C, class MultiIndex, class IsFinal>

decltype(auto) Dune::Functions::resolveDynamicMultiIndex | ( | C && | c,
|  | const MultiIndex & | multiIndex,
|  | const IsFinal & | isFinal )

constexpr

Provide multi-index access by chaining operator[].

This provides access to a nested container by given dynamically sized multi-index. Internally this is resolved by recursive operator[]-calls with static or dynamic indices. Because this recursion must be terminated, a predicate is used to determine if a type is considered final for the multi-index resolution. Hence multi-index resolution is terminated for values where the criterion matches. In order to do this statically the predicate has to return its result as std::true_type or std::false_type.

If the entries of the multi-index are exhausted, additional [0] entries are used until the termination criterion is satisfied.

Parameters

  c | Container to access
  multiIndex | Multi-index
  isFinal | A predicate function checking if recursion should be terminated.

## resolveStaticMultiIndex()

template<class C, class MultiIndex>

decltype(auto) Dune::Functions::resolveStaticMultiIndex | ( | C && | c,
|  | const MultiIndex & | multiIndex )

constexpr

Provide multi-index access by chaining operator[].

This provides access to a nested container by given statically sized multi-index. Internally this is resolved by recursive operator[]-calls with static or dynamic indices. Since the multi-index must have compile-time known size it is possible, that values resolved by different multi-indices have a different size.

Parameters

  c | Container to access
  multiIndex | Multi-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 `Dune::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.

## 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

  f | A functor defined for all tuple entries
  tuple | The 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

  f | A functor defined for all tuple entries
  tuple1 | The tuple containing values for the first parameter
  tuple2 | The tuple containing values for the second parameter