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

Ensure unstable_remove_if calls the predicate exactly once per element #1629

Merged
merged 1 commit into from
Sep 12, 2021
Merged

Ensure unstable_remove_if calls the predicate exactly once per element #1629

merged 1 commit into from
Sep 12, 2021

Conversation

mjbeardsley
Copy link
Contributor

There are cases where unstable_remove_if can call the predicate on the converged-upon "partition element" twice:
https://godbolt.org/z/a8W5oWr3T

It should have the same guarantee as remove_if:

https://en.cppreference.com/w/cpp/algorithm/remove

Complexity
Exactly std::distance(first, last) applications of the predicate.

https://en.cppreference.com/w/cpp/algorithm/ranges/remove

Complexity
Exactly N applications of the corresponding predicate and any projection, where N = (last - first), and N-1 move operations at worst.

There are cases where unstable_remove_if can call the predicate on the converged-upon "partition element" twice:
https://godbolt.org/z/a8W5oWr3T

It should have the same guarantee as remove_if:

https://en.cppreference.com/w/cpp/algorithm/remove
> Complexity
> Exactly std::distance(first, last) applications of the predicate.

https://en.cppreference.com/w/cpp/algorithm/ranges/remove
> Complexity
> Exactly N applications of the corresponding predicate and any projection, where N = (last - first), and N-1 move operations at worst.
@ericniebler
Copy link
Owner

Wow, nice find!

@ericniebler ericniebler merged commit 9b07682 into ericniebler:master Sep 12, 2021
@mjbeardsley mjbeardsley deleted the unstable_remove_if_num_pred_calls branch September 12, 2021 19:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants