Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

variadic min/max/minmax #119

Open
gpeterhoff opened this issue Jun 24, 2023 · 1 comment
Open

variadic min/max/minmax #119

gpeterhoff opened this issue Jun 24, 2023 · 1 comment

Comments

@gpeterhoff
Copy link

Hello,
for min/max/minmax with multiple parameters there are only functions per std::initializer_list:
https://en.cppreference.com/w/cpp/algorithm/min
https://en.cppreference.com/w/cpp/algorithm/max
https://en.cppreference.com/w/cpp/algorithm/minmax
The parameters are always passed by value and not by reference and the result is also a value. This is a problem with types like std::array, std::string, etc.

Since the compare class cannot be the last function parameter in a variadic implementation (as in the std implementations) another position must be found, possibilities:

  • first function parameter: 2 implementations would be needed each, once with compare class and once without. I don't find that useful.
  • first template parameter: only one implementation is needed with default template parameter(s).

A simple variadic implementation could look like this:
minmax_variadic.hpp.txt

minmax needs 2 compare classes (each for min and max) - this is more flexible.

thx
Gero

@mclow
Copy link
Collaborator

mclow commented Jun 27, 2023

There is also std::minmax_element, which takes a sequence.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants