https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100387
--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> --- The releases/gcc-11 branch has been updated by Patrick Palka <ppa...@gcc.gnu.org>: https://gcc.gnu.org/g:927548b42c4850094eb41c7ae882cbe219b24231 commit r11-8728-g927548b42c4850094eb41c7ae882cbe219b24231 Author: Patrick Palka <ppa...@redhat.com> Date: Fri Jun 18 19:33:39 2021 -0400 libstdc++: Reduce ranges::minmax/minmax_element comparison complexity This rewrites ranges::minmax and ranges::minmax_element so that it performs at most 3*N/2 many comparisons, as required by the standard. In passing, this also fixes PR100387 by avoiding a premature std::move in ranges::minmax and in std::shift_right. PR libstdc++/100387 libstdc++-v3/ChangeLog: * include/bits/ranges_algo.h (__minmax_fn::operator()): Rewrite to limit comparison complexity to 3*N/2. (__minmax_element_fn::operator()): Likewise. (shift_right): Avoid premature std::move of __result. * testsuite/25_algorithms/minmax/constrained.cc (test04, test05): New tests. * testsuite/25_algorithms/minmax_element/constrained.cc (test02): Likewise. (cherry picked from commit cc9c94d43dcfa98436152af9c00f011e9dab25f6)