Skip to content

Add missed increment of _Current in the early return path - #1561

Merged
Stephan T. Lavavej (StephanTLavavej) merged 3 commits into
microsoft:masterfrom
miscco:fix_ranges_unique
Jan 15, 2021
Merged

Add missed increment of _Current in the early return path#1561
Stephan T. Lavavej (StephanTLavavej) merged 3 commits into
microsoft:masterfrom
miscco:fix_ranges_unique

Conversation

@miscco

Copy link
Copy Markdown
Contributor

Fixes #1560

When avoiding an superfluous comparison we missed to add the necessary increment to exclude the first element of the last group.

@StephanTLavavej Stephan T. Lavavej (StephanTLavavej) added bug Something isn't working ranges C++20/23 ranges labels Jan 8, 2021

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this correctness bug! I'll push a small comment change.

Comment thread tests/std/tests/P0896R4_ranges_alg_unique/test.cpp Outdated
Comment thread tests/std/tests/P0896R4_ranges_alg_unique/test.cpp Outdated

auto result = unique(wrapped_input.begin(), wrapped_input.end(), countedEq, get_second);
STATIC_ASSERT(same_as<decltype(result), subrange<iterator_t<ReadWrite>>>);
assert(result.empty());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Observation, no change requested: This could be more strict, by verifying that the empty subrange is at the end. However, it's unlikely that we'll damage this (and this PR certainly isn't), so it's just something to keep in mind for future tests.

@miscco

Copy link
Copy Markdown
Contributor Author

Thanks a lot Stephan T. Lavavej (@StephanTLavavej)

@StephanTLavavej

Copy link
Copy Markdown
Member

Thanks for this uniquely awesome bugfix! 😹 🪲

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.

<algorithm>: std::ranges::unique returns the wrong value for already unique input

3 participants