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

Add find_min/max/minmax algorithms #112

Closed
tcbrindle opened this issue Aug 2, 2023 · 0 comments · Fixed by #113
Closed

Add find_min/max/minmax algorithms #112

tcbrindle opened this issue Aug 2, 2023 · 0 comments · Fixed by #113
Labels
enhancement New feature or request

Comments

@tcbrindle
Copy link
Owner

C++20 provides both std::ranges::min() (an overload of which takes an input range and returns the value of the least element) and std::ranges::min_element() (which takes a forward range and returns an iterator to the least element).

In Flux we currently have flux::min() which is the equivalent of the first function, except that we return an optional to avoid UB in the case where the sequence is empty.

We should also provide an equivalent for min_element(), taking a multipass_sequence and returning a cursor to the least element. Because we use the term "element" in Flux to mean a member of a sequence in general, reusing the standard library function name could be confusing, so instead we'll go for find_min() -- which makes it clear that it's returning a cursor, like the rest of the find() family.

Of course, we should have find_max() and find_minmax() (returning a pair of cursors) too.

Related: #101

@tcbrindle tcbrindle added the enhancement New feature or request label Aug 3, 2023
tcbrindle added a commit that referenced this issue Aug 4, 2023
These do the same as `min()`/`max()`/`minmax()`, but take multipass sequences and return a cursor to the requisite elements rather than an optional value, returning a past-the-end cursor if the input sequence is empty.

Fixes #112
tcbrindle added a commit that referenced this issue Aug 4, 2023
These do the same as `min()`/`max()`/`minmax()`, but take multipass sequences and return a cursor to the requisite elements rather than an optional value, returning a past-the-end cursor if the input sequence is empty.

Fixes #112
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant