Skip to content

Make Hybrid::switchCases more hybrid

Simon Praetorius requested to merge feature/hybrid-switch-cases into master

Summary

This MR adds two overloads of Hybrid::switchCases using StaticIntegralRange and IntegralRange. These two ranges can be easily constructed using the range utility Dune::range(size) with size an integer or an integral_constant. Making the switchCases utility more hybrid by allowing dynamic ranges with dynamic indices makes writing generic code more flexible.

For the implementation to work, the IntegralRange and staticIntegralRange are extended by a contains(value) method to check whether value is contained in that range.

Example:

Accessing an entry in a vector

Dune::Hybrid::switchCases(Dune::range(Dune::Hybrid::size(vector)), index, [&](auto ii) {
  // do something with vector[ii]
});

where the vector can be a MultiTypeVector or a TupleVector or a std::vector or...

Edited by Simon Praetorius

Merge request reports

Loading