-
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
Unwrapping output iterators in range algorithms #5015
Merged
StephanTLavavej
merged 19 commits into
microsoft:main
from
CaseyCarter:ranges-output-unwrapping
Oct 17, 2024
Merged
Unwrapping output iterators in range algorithms #5015
StephanTLavavej
merged 19 commits into
microsoft:main
from
CaseyCarter:ranges-output-unwrapping
Oct 17, 2024
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CaseyCarter
force-pushed
the
ranges-output-unwrapping
branch
from
October 14, 2024 06:27
cd75c40
to
fd21582
Compare
* Add `_Distance_unbounded` to represent the distance between an iterator and `unreachable_sentinel`. * `_Idl_distance` takes iterator/sentinel pairs in C++20 mode. * Add `_RANGES _Idl_distance(range)`, equivalent to `_STD _Idl_distance` but for `sized_range` instead of `sized_sentinel_for`. * Support integer-class counts in `_Get_unwrapped_n`.
Now that `_Get_unwrapped_n` supports integer-class counts, we don't need to apply `_Algorithm_int_t` to `_Count`.
* Refactor `_Idl_dist_add`: * Use `if constexpr` dispatch instead of overloading. * `_Distance_unbounded` plus anything is `_Distance_unbounded`. * Implement `_Idl_dist_min` to compute the smaller of two `_Idl_distance`s.
…_Output` This changes our convention. I think `_Output` is more appropriate than `_Result` for this purpose given that most algorithms produce more results than just the output sequence. This also makes `_Result` unambiguously available to refer to the return value of the algorithm which is consistent with our use of `_UResult` for intermediate unwrapped results.
These tests failed because an iterator claims to be random-access without supporting subtraction, which breaks with our pre-C++20 `_Idl_distance`. C++20-and-later `_Idl_distance` isn't fooled by such shenanigans. (We only test libc++ in `/std:c++latest` mode.)
CaseyCarter
force-pushed
the
ranges-output-unwrapping
branch
from
October 14, 2024 07:32
fd21582
to
0b2139b
Compare
StephanTLavavej
added
performance
Must go faster
and removed
enhancement
Something can be improved
labels
Oct 14, 2024
StephanTLavavej
requested changes
Oct 14, 2024
StephanTLavavej
approved these changes
Oct 15, 2024
I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed. |
Thanks for this long-awaited improvement! 😻 🪄 🎉 |
CaseyCarter
added a commit
to CaseyCarter/STL
that referenced
this pull request
Oct 18, 2024
microsoft#5015 unskipped these, they now go through the same old codepath.
CaseyCarter
added a commit
to CaseyCarter/STL
that referenced
this pull request
Oct 27, 2024
…gative counts * `ranges::copy_n` takes a difference argument that it was blindly converting to `size_t` Drive-by: `_Copy_n_unchecked4` no longer needs to guard its `_STL_INTERNAL_STATIC_ASSERT(_Integer_like<_SizeTy>);` for `_HAS_CXX20` since microsoft#5015 defined `_Integer_like` in pre-20 modes.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This completes the last bits of the iterator unwrapping design for Ranges algorithms.
Detailed commit-wise description:
Expand
_Idl_distance
design for Ranges_Distance_unbounded
to represent the distance between an iterator andunreachable_sentinel
._Idl_distance
takes iterator/sentinel pairs in C++20 mode._RANGES _Idl_distance(range)
, equivalent to_STD _Idl_distance
but forsized_range
instead ofsized_sentinel_for
._Get_unwrapped_n
.Simplify
ranges::destroy_n
. Now that_Get_unwrapped_n
supports integer-class counts, we don't need to apply_Algorithm_int_t
to_Count
.Update operations on
_Idl_distance
s_Idl_dist_add
:if constexpr
dispatch instead of overloading._Distance_unbounded
plus anything is_Distance_unbounded
._Idl_dist_min
to compute the smaller of two_Idl_distance
s.Rename Range algorithm output iterator parameters from
_Result
to_Output
. This changes our convention. I think_Output
is more appropriate than_Result
for this purpose given that most algorithms produce more results than just the output sequence. This also makes_Result
unambiguously available to refer to the return value of the algorithm which is consistent with our use of_UResult
for intermediate unwrapped results.Unwrap outputs in
ranges::copy
Unwrap outputs in
ranges::copy_backward
Unwrap outputs in
ranges::copy_if
Unwrap outputs in
ranges::copy_n
Unwrap outputs in
ranges::merge
Unwrap outputs in
ranges::move
Unwrap outputs in
ranges::move_backward
Unwrap outputs in
ranges::replace_copy
Unwrap outputs in
ranges::replace_copy_if
Unwrap outputs in
ranges::reverse_copy
Unwrap outputs in
ranges::rotate_copy
Unwrap outputs in
ranges::sample
Unwrap outputs in
ranges::transform
(The warning suppression is necessary to prevent the static analyzer diagnosing the computation of_Min_size_determinable
as redundant when_Rng1
and_Rng2
are the same type.)Fixes #893.