Extrema
Min/max functions that can compare values of different types.
Caution
Imports <concepts>, <type_traits> and <utility>.
Tip
To import use #include "atl/compare/extrema.hpp".
abl::min and abl::max
If the types of the arguments are the same, the function returns constant reference to the smaller/larger value. Otherwise, the function returns the smaller/larger value by value of the common type.
abl::min(a, b);
abl::max(a, b);abl::minmax
Returns a pair of the smaller and larger values. If the types of the arguments are different, both elements in the pair are converted to the common type.
abl::minmax(a, b);With a custom comparator
You can also use a custom comparator function to compare the values.
Note
a is considered “better” in terms of the function if the comparator returns true when comparing a and b, i.e. the result of calling abl::min and abl::max with the same comparator is the same.
abl::min(a, b, [](auto a, auto b) { return a < b; });
abl::max(a, b, [](auto a, auto b) { return a > b; });
abl::minmax(a, b, [](auto a, auto b) { return a < b; });