Daily bit(e) of C++ | std::min_element, std::max_element and std::minmax_element
Daily bit(e) of C++ #202, The min-max algorithms that operate on top of iterators: std::min_element, std::max_element and std::minmax_element.
The std::min_element, std::max_element and (C++11) std::minmax_element are min-max algorithms that operate on top of iterators, returning an iterator to the minimum/maximum element.
The algorithms provide parallel (C++17) variants and are constexpr and range enabled (C++20).
C++20 also offers a simpler alternative: a range overload of the base min-max algorithms.
I love the projection thing in ranges. Once you get used to it (reading/writing the code) it's really nice.
What does the `{}` in the line `auto it = std::ranges::min_element(elements, {}, &Element::v);` refer to?
The documentation states "comparison to apply to the projected elements", however, as a newbie, that is like a foreign language to me.
Ref: https://en.cppreference.com/w/cpp/algorithm/ranges/min_element