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

<algorithm>: ranges::minmax should dereference iterators only once #3366

Merged
merged 17 commits into from
Feb 3, 2023
Merged
4 changes: 2 additions & 2 deletions stl/inc/algorithm
Original file line number Diff line number Diff line change
Expand Up @@ -10104,8 +10104,8 @@ namespace ranges {
_STD move(_UFirst), _STD move(_ULast), _Pass_fn(_Pred), _Pass_fn(_Proj));
// Avoid repeatedly initializing objects from the result of an iterator dereference when doing so might
// not be idempotent. The `if constexpr` to avoid the extra branch in cases where it's not needed
StephanTLavavej marked this conversation as resolved.
Show resolved Hide resolved
if constexpr (same_as<remove_cvref_t<range_reference_t<_Rng>>, _Vty>
&& !is_lvalue_reference_v<range_reference_t<_Rng>>) {
if constexpr (!same_as<remove_cvref_t<range_reference_t<_Rng>>, _Vty>
|| !is_lvalue_reference_v<range_reference_t<_Rng>>) {
CaseyCarter marked this conversation as resolved.
Show resolved Hide resolved
if (_Found.min == _Found.max) {
fsb4000 marked this conversation as resolved.
Show resolved Hide resolved
// This initialization is correct, similar to WG21-N4928 [dcl.init.aggr]/6 example
StephanTLavavej marked this conversation as resolved.
Show resolved Hide resolved
minmax_result<_Vty> _Result = {static_cast<_Vty>(*_Found.min), _Result.min};
Expand Down