Hybrid utility functions that work on homogeneous as well as heterogeneous containers.
More...
|
template<class T > |
constexpr auto | Dune::Hybrid::size (const T &t) |
| Size query.
|
|
template<class Container , class Index > |
constexpr decltype(auto) | Dune::Hybrid::elementAt (Container &&c, Index &&i) |
| Get element at given position from container.
|
|
template<class Begin , class End > |
constexpr auto | Dune::Hybrid::integralRange (const Begin &begin, const End &end) |
| Create an integral range.
|
|
template<class End > |
constexpr auto | Dune::Hybrid::integralRange (const End &end) |
| Create an integral range starting from 0.
|
|
template<class Range , class F > |
constexpr void | Dune::Hybrid::forEach (Range &&range, F &&f) |
| Range based for loop.
|
|
template<class Range , class T , class F > |
constexpr T | Dune::Hybrid::accumulate (Range &&range, T value, F &&f) |
| Accumulate values.
|
|
template<class Condition , class IfFunc , class ElseFunc > |
decltype(auto) | Dune::Hybrid::ifElse (const Condition &condition, IfFunc &&ifFunc, ElseFunc &&elseFunc) |
| A conditional expression.
|
|
template<class Condition , class IfFunc > |
void | Dune::Hybrid::ifElse (const Condition &condition, IfFunc &&ifFunc) |
| A conditional expression.
|
|
template<class T1 , class T2 > |
constexpr auto | Dune::Hybrid::equals (T1 &&t1, T2 &&t2) |
| Equality comparison.
|
|
template<class Cases , class Value , class Branches , class ElseBranch > |
constexpr decltype(auto) | Dune::Hybrid::switchCases (const Cases &cases, const Value &value, Branches &&branches, ElseBranch &&elseBranch) |
| Switch statement.
|
|
template<class Cases , class Value , class Branches > |
constexpr void | Dune::Hybrid::switchCases (const Cases &cases, const Value &value, Branches &&branches) |
| Switch statement.
|
|
Hybrid utility functions that work on homogeneous as well as heterogeneous containers.
template<class Condition , class IfFunc , class ElseFunc >
decltype(auto) Dune::Hybrid::ifElse |
( |
const Condition & |
condition, |
|
|
IfFunc && |
ifFunc, |
|
|
ElseFunc && |
elseFunc |
|
) |
| |
A conditional expression.
This will call either ifFunc or elseFunc depending on the condition. In any case a single argument will be passed to the called function. This will always be the identity function. Passing an expression through this function will lead to lazy evaluation. This way both 'branches' can contain expressions that are only valid within this branch if the condition is a std::integral_constant<bool,*>.
In order to do this, the passed functors must have a single argument of type auto.
Due to the lazy evaluation mechanism and support for std::integral_constant<bool,*> this allows to emulate a static if statement.
template<class Cases , class Value , class Branches >
constexpr void Dune::Hybrid::switchCases |
( |
const Cases & |
cases, |
|
|
const Value & |
value, |
|
|
Branches && |
branches |
|
) |
| |
|
constexpr |
Switch statement.
- Template Parameters
-
Cases | Type of case range |
Value | Type of value to check against the cases |
Branches | Type of branch function |
- Parameters
-
cases | A range of cases to check for |
value | The value to check against the cases |
branches | A callback that will be executed with matching entry from case list |
Value is checked against all entries of the given range. If one matches, then branches is executed with the matching value as single argument. If the range is an std::integer_sequence, the value is passed as std::integral_constant. If non of the entries matches, then elseBranch is executed without any argument.
template<class Cases , class Value , class Branches , class ElseBranch >
constexpr decltype(auto) Dune::Hybrid::switchCases |
( |
const Cases & |
cases, |
|
|
const Value & |
value, |
|
|
Branches && |
branches, |
|
|
ElseBranch && |
elseBranch |
|
) |
| |
|
constexpr |
Switch statement.
- Template Parameters
-
Cases | Type of case range |
Value | Type of value to check against the cases |
Branches | Type of branch function |
ElseBranch | Type of branch function |
- Parameters
-
cases | A range of cases to check for |
value | The value to check against the cases |
branches | A callback that will be executed with matching entry from case list |
elseBranch | A callback that will be executed if no other entry matches |
Value is checked against all entries of the given range. If one matches, then branches is executed with the matching value as single argument. If the range is an std::integer_sequence, the value is passed as std::integral_constant. If non of the entries matches, then elseBranch is executed without any argument.
Notice that this short circuits, e.g., if one case matches, the others are no longer evaluated.
The return value will be deduced from the else branch.