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

Implement (chunk_view<forward>|stride_view)::iterator::operator(\+=|-=) in O(1) #3023

Merged
merged 3 commits into from
Aug 12, 2022

Conversation

CaseyCarter
Copy link
Member

@CaseyCarter CaseyCarter commented Aug 10, 2022

Speculatively implements what will be the proposed resolution of an LWG issue filed per GH-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 #2995

…-=)` 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
@CaseyCarter CaseyCarter added bug Something isn't working ranges C++20/23 ranges labels Aug 10, 2022
@CaseyCarter CaseyCarter requested a review from a team as a code owner August 10, 2022 20:32
@CaseyCarter CaseyCarter changed the title Implement `(chunk_view<forward>|stride_view)::iterator::operator(\+=|… Implement (chunk_view<forward>|stride_view)::iterator::operator(\+=|-=) in O(1) Aug 10, 2022
stl/inc/ranges Outdated Show resolved Hide resolved
stl/inc/ranges Outdated Show resolved Hide resolved
Co-authored-by: S. B. Tam <cpplearner@outlook.com>
@StephanTLavavej
Copy link
Member

Thanks @cpplearner - as both sites require random_access_range I've changed them to subtract.

@strega-nil-ms strega-nil-ms self-assigned this Aug 11, 2022
@StephanTLavavej StephanTLavavej self-assigned this Aug 11, 2022
@StephanTLavavej
Copy link
Member

I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed.

@StephanTLavavej StephanTLavavej merged commit fea2b8c into microsoft:main Aug 12, 2022
@StephanTLavavej
Copy link
Member

Thanks for fixing chunks of this bug and helping the STL stride forward into a new era! 😹 👟 🚀

@CaseyCarter CaseyCarter deleted the chunk-stride branch August 13, 2022 06:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working ranges C++20/23 ranges
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants