std::min_elementand std::max_elementyou must go through the entire container before they are returned. If you use std::min_element, then std::max_elementthese are two workarounds, whereas if you use std::minmax_element, you only need one.
So, it is “easy” to save comparisons, but I think that halving the amount of work you need to get the necessary data without losing clarity is very useful.
source
share