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 find_min/max/minmax algorithms #112

Closed tcbrindle closed 1 year ago

tcbrindle commented 1 year ago

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