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

Simplify the comparison of sizes of different ranges #4864

Merged
merged 1 commit into from
Aug 8, 2024

Conversation

hewillk
Copy link
Contributor

@hewillk hewillk commented Jul 26, 2024

Explicit casting of the result of ranges::size is too verbose; simply comparing the values ​​of ranges::distance is sufficient as they are guaranteed to be signed integers.
This aligns with the implementation in ranges::is_permutation:

STL/stl/inc/algorithm

Lines 1084 to 1088 in 8657d15

if constexpr (sized_range<_Rng1> && sized_range<_Rng2>) {
const auto _Count = _RANGES distance(_Range1);
if (_RANGES distance(_Range2) != _Count) {
return false;
}

@hewillk hewillk requested a review from a team as a code owner July 26, 2024 15:44
@StephanTLavavej StephanTLavavej added enhancement Something can be improved ranges C++20/23 ranges labels Jul 30, 2024
@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 bdcd8ea into microsoft:main Aug 8, 2024
39 checks passed
@StephanTLavavej
Copy link
Member

Thanks for this nice simplification! 🪄 😸 🐈‍⬛

@hewillk hewillk deleted the main-size branch August 8, 2024 07:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Something can be improved ranges C++20/23 ranges
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants