Skip to content

Explicitly commit to a type in std::min and std::max

Simon Praetorius requested to merge issue/min-sizes into master

Summary

The utilities std::min and std::max are templates parametrized with a single template parameter that must match for both arguments to allow template argument deduction. In some cases this is not trivial, since the two arguments come from different parts of the library or completely different objects. An example where it fails can be found in pipelien https://gitlab.dune-project.org/core/dune-common/-/jobs/561968 where the size of FieldVector is compared against the size of an initializer_list. If we change the FieldVector implementation, the code fails as seen in the error message. A simple solution is the explicit instantiation of the std::min and std::max templates. That way they are turned into regular function where argument conversion happens and a signed integer can be passed to an unsigned integer, etc.

This MR unifies the usage of std::min and std::max where the argument come from different contexts, to always commit explicitly to a type.

Edited by Simon Praetorius

Merge request reports

Loading