Skip to content

Add hybrid operators for plus, minus, max, and min

Santiago Ospina De Los Ríos requested to merge feature/hybrid-operators into master

Description

This MR implements lambda operators that work on hybrid types. This is useful when one does not know whether a templated type is run-time or compile-time value. If all the operators' arguments are integral constants, the result will also be an integral constant. Otherwise, they will be downcasted to run-time values.

using namespace Dune::Indices;
auto r1 = Hybrid::plus(_1,_2); // -> std::integral_constant<std::size_t,3>
auto r2 = Hybrid::plus( 1,_2); // -> std::size_t (maybe constexpr)
auto r3 = Hybrid::plus( 1, 2); // -> std::size_t (maybe constexpr)

In particular, this MR adds operators for Hybrid::max, Hybrid::min, Hybrid::plus, Hybrid::minus, and adapts Hybrid::equals to use the same engine.

Discussion

A discussion point is if it's OK to change Hybrid::equals from being a function to a lambda. Personally, I prefer lambdas because they can be passed around without any specific template signature while allowing the operator to be generic. Maybe there is some issue that may appear if this change is made.

  • Add changelog entry
Edited by Santiago Ospina De Los Ríos

Merge request reports