-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
<ranges>
: stride_view::iterator::operator+=
could have O(N) complexity
#2995
Comments
The first fix sounds good to me (and we'll need to fix this for I don't think the |
stride_view::iterator::operator+=
could have O(N) complexity<ranges>
: stride_view::iterator::operator+=
could have O(N) complexity
…-=)` in O(1) Speculatively implements what will be the proposed resolution of an LWG issue filed per microsoftGH-2995 once the new working draft is out with `stride_view` and `chunk_view`. Also avoid checking the precondition when it can't be done in O(1). Drive-by: * inline `ranges::advance(i, n)` since it's simply `i += n` for random-access iterators * check for overflow of `-n` when calling `*this += -n` in `operator-=` Partially addresses microsoft#2995
LWG isn't really equipped to track issues in things that don't appear yet in a working draft. |
|
If the iterator and sentinel types of the underlying view type don't model
sized_sentinel_for
, theranges::advance
call depicted in the "Effects: Equivalent to" code:has O(n) complexity. However, all operations on conforming random-access iterators must have O(1) complexity. This can perhaps be fixed by advancing the iterator in two steps:
Which has complexity
O(stride_)
. (Admittedly icky, especially whenstride_
is nearn
.)Alternatively, we could additionally require
sized_sentinel_for<sentinel_t<Base>, iterator_t<Base>>
foriterator
to modelrandom_access
, which would ensure that the problematicadvance
call is O(1).The text was updated successfully, but these errors were encountered: