Loading...
Searching...
No Matches
Dune::Hybrid::HybridFunctor< Functor > Class Template Reference
Common » Utilities » Hybrid Utilities

Adapter of a hybrid functor that maintains results hybrid. More...

`#include <dune/common/hybridutilities.hh>`

## Public Member Functions

template<class... Args>
constexpr decltype(auto) | operator() (const Args &... args) const
| Adapter of a hybrid functor that keeps results hybrid.

## Detailed Description

template<class Functor>
class Dune::Hybrid::HybridFunctor< Functor >

Adapter of a hybrid functor that maintains results hybrid.

This adapter will return an integral constant if all of the arguments are integral constants. That's helpful to maintain the hybrid nature of a variable after a transformation. For example, applying an operator + between two integral constants will promote the result to its underlying type (e.g. std::size_t). That's inconvenient since the value of the result is not encoded in the type anymore, thus, losing its hybrid attribute (maybe still being constexpr).

using namespace Dune::Indices;
{ // non-hybrid transformation!
auto i = 1 + 2; // -> 3
auto j = 1 + _2; // -> 3
auto k = _1 + _2; // -> 3
// depending of the context, `k` may or may not be constexpr
}
{ // hybrid transformation!
auto plus = Hybrid::HybridFunctor<std::plus<>>{};
auto j = plus( 1, 2); // -> 3
auto j = plus( 1, _2); // -> 3
auto k = plus(_1, _2); // -> Dune::Indices::_3
// independent of the context, `k` encodes its value in the type system
}
Dune::Indices::_1
constexpr index_constant< 1 > _1
Compile time index with value 1.
Definition indices.hh:55
Dune::Indices::_2
constexpr index_constant< 2 > _2
Compile time index with value 2.
Definition indices.hh:58
Dune::Hybrid::plus
constexpr auto plus
Function object for performing addition.
Definition hybridutilities.hh:533
Dune::Indices
Namespace with predefined compile time indices for the range [0,19].
Definition indices.hh:50
Dune::Hybrid::HybridFunctor
Adapter of a hybrid functor that maintains results hybrid.
Definition hybridutilities.hh:423

The documentation for this class was generated from the following file:

- hybridutilities.hh