You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[libc++] std::ranges::advance: avoid unneeded bounds checks when advancing iterator (#84126)
Currently, the bounds check in `std::ranges::advance(it, n, s)` is done
_before_ `n` is checked. This results in one extra, unneeded bounds
check.
Thus, `std::ranges::advance(it, 1, s)` currently is _not_ simply
equivalent to:
```c++
if (it != s) {
++it;
}
```
This difference in behavior matters when the check involves some
"expensive" logic. For example, the `==` operator of
`std::istreambuf_iterator` may actually have to read the underlying
`streambuf`.
Swapping around the checks in the `while` results in the expected
behavior.
Copy file name to clipboardExpand all lines: libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.advance/iterator_count_sentinel.pass.cpp
+59-17Lines changed: 59 additions & 17 deletions
Original file line number
Diff line number
Diff line change
@@ -21,9 +21,12 @@
21
21
#include"../types.h"
22
22
23
23
template <bool Count, typename It>
24
-
constexprvoidcheck_forward(int* first, int* last, std::iter_difference_t<It> n, int* expected) {
24
+
constexprvoid
25
+
check_forward(int* first, int* last, std::iter_difference_t<It> n, int* expected, int expected_equals_count = -1) {
0 commit comments