tcbrindle / flux

A C++20 library for sequence-orientated programming
https://tristanbrindle.com/flux/
Boost Software License 1.0
472 stars 29 forks source link

Add cmp::min cmp::max #115

Closed tcbrindle closed 1 year ago

tcbrindle commented 1 year ago

Because they're ordinary function templates, std::min and std::max can't be passed as arguments to functions without wrapping them in lambdas (or doing a horrible function pointer cast). This makes me sad.

std::ranges::min and std::ranges::max are function objects and so can be passed as function arguments -- except with MSVC, which annoyingly goes out of its way to prevent you doing this very useful thing. This also makes me sad.

To improve matters, we'll add flux::cmp::min and flux::cmp::max which take two arguments and an optional comparator and return the lesser and greater respectively.

As an added bonus, max() now correctly returns the second argument if both are equal, and our versions of these functions should be less likely than the standard versions to cause dangling when used with rvalues.

codecov[bot] commented 1 year ago

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (e83bdcb) 97.58% compared to head (44a3078) 97.58%. Report is 2 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #115 +/- ## ======================================= Coverage 97.58% 97.58% ======================================= Files 66 66 Lines 2276 2280 +4 ======================================= + Hits 2221 2225 +4 Misses 55 55 ``` | [Files Changed](https://app.codecov.io/gh/tcbrindle/flux/pull/115?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Tristan+Brindle) | Coverage Δ | | |---|---|---| | [include/flux/core/functional.hpp](https://app.codecov.io/gh/tcbrindle/flux/pull/115?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Tristan+Brindle#diff-aW5jbHVkZS9mbHV4L2NvcmUvZnVuY3Rpb25hbC5ocHA=) | `100.00% <100.00%> (ø)` | |

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.