Skip to content

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

Merged
StephanTLavavej merged 3 commits into
microsoft:mainfrom
CaseyCarter:chunk-stride
Aug 12, 2022
Merged

Implement (chunk_view<forward>|stride_view)::iterator::operator(\+=|-=) in O(1)#3023
StephanTLavavej merged 3 commits into
microsoft:mainfrom
CaseyCarter:chunk-stride

Conversation

@CaseyCarter
Copy link
Copy Markdown
Contributor

@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
Comment thread stl/inc/ranges Outdated
Comment thread stl/inc/ranges Outdated
@StephanTLavavej
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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