Closed DivineDominion closed 8 months ago
Please double check, I fear I might miss something :)
I was looking at the .h file on the website:
template <typename T, typename Compare> // Compare is StrictWeakOrdering on type T inline const T& min(const T& a, const T& b, Compare cmp) { if (cmp(b, a)) { return a; } else { return b; } }
so min(1, 2) would then eventually be evaluated as this (substituting all parameters):
min(1, 2)
const int min(1, 2, less) { if (less(2, 1)) { return 1; } else { return 2; } }
less(2,1) will be false, so the else branch executes, returning 2.
less(2,1)
2
Read the rest of the script more closely, then. The fixed implementation further above is:
So let’s correct it, so we don’t swap unless necessary. if (b < a) { return b; } else { return a; }
So let’s correct it, so we don’t swap unless necessary.
if (b < a) { return b; } else { return a; }
It should definitely be b in the if branch.
b
if
This PR corrects the assembled template to match the corrected algorithm.
https://www.youtube.com/watch?v=9S-Lh2J8_LU&t=2060s
Thanks to @oliverepper for digging up the timestamp
Thanks! There must have been a mix up, because all the source material agrees with you.
Please double check, I fear I might miss something :)
I was looking at the .h file on the website:
so
min(1, 2)
would then eventually be evaluated as this (substituting all parameters):less(2,1)
will be false, so the else branch executes, returning2
.Read the rest of the script more closely, then. The fixed implementation further above is:
It should definitely be
b
in theif
branch.This PR corrects the assembled template to match the corrected algorithm.