You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Apply the predicate of ranges::remove_if and remove to the projected type - #8201
hpx::ranges::remove_if without an execution policy (iterator/sentinel and range) now checks the predicate against the projected type, with is_indirect_callable_v<sequenced_policy, Pred, projected<Proj, Iter>>, the way the overloads that take a policy already do.
The four overloads of hpx::ranges::remove compare the value with what the projection yields; the lambda no longer names the element type.
Regression tests in remove_if_range.cpp and remove_range.cpp that project a struct to an int member, for the iterator/sentinel and range forms, with and without a policy.
Any background context you want to provide?
With a projection that changes the type, such as &item::id, six of the eight overloads did not compile, while std::ranges::remove_if / std::ranges::remove accept the same calls. Details and a reproducer are in #8200. It is the same kind of problem as #8155 and #8156, in a file those do not touch.
Checked with GCC 15.2 (C++20, local runtime): the reproducer from the issue compiles, and remove_range_test and remove_if_range_test pass with the new cases.
Checklist
Not all points below apply to all pull requests.
I have added a new feature and have added tests to go along with it.
I have fixed a bug and have added a regression test.
I have added a test using random numbers; I have made sure it uses a seed, and that random numbers generated are valid inputs for the tests.
No actionable comments were generated in the recent review.
Summary
Summary by CodeRabbit
Bug Fixes
Corrected range-based remove and remove_if behavior when using projections, across iterator-pair and range overloads.
Improved compatibility with predicates that accept projected reference types.
Tests
Expanded coverage for projected removal with sequential and parallel execution policies, checking the returned range and retained items.
The remove overloads derive the comparison value type from the projection result. The remove_if constraints check predicate and projection compatibility. Regression tests cover projected removal by item ID across iterator, range, and execution-policy overloads.
The remove overloads derive their default value type from the projection result and use generic equality predicates. The remove_if constraints check indirect predicate and projection callability.
TheHPXProject/hpx#7947: Both changes affect value comparison in remove; this PR changes comparison to use the projection result.
Suggested reviewers:msimberg
Merge Risk: Minimal · up to fc55f
This change lets hpx::ranges::remove and remove_if accept projections that yield a different type from the element type. No actionable merge risk was found, and regression tests cover the affected overloads.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names the main change: the predicate of ranges::remove_if and remove is now applied to the projected type. The changeset matches this. The raw summary describes the default T change, t…
Description check
The description is related to the changeset. It references issue #8200 and states that the no-policy remove_if overloads now check the predicate against the projected type. It also says the four `re…
Linked Issues check
Issue #8200 has two coding requirements. Both are implemented in remove.hpp at the reviewed head, compared with the merge base 5d08dcd.
(1) [#8200] No-policy remove_if (iterator/sentinel and range ov…
Out of Scope Changes check
The whole-PR diff changes only remove.hpp among the algorithm headers. Those changes affect the constraints, default template arguments, and lambdas of remove_if and remove. These are the overloads na…
Full details: Title check
Explanation
The title names the main change: the predicate of ranges::remove_if and remove is now applied to the projected type. The changeset matches this. The raw summary describes the default T change, the is_indirect_callable_v constraint for no-policy remove_if, and the lambda change in remove. The new tests cover projection to an int member. The title is specific and concise, and it does not name the issue number.
Full details: Description check
Explanation
The description is related to the changeset. It references issue #8200 and states that the no-policy remove_if overloads now check the predicate against the projected type. It also says the four remove overloads compare the value with the projection result. It lists regression tests in remove_if_range.cpp and remove_range.cpp, which match the raw summary. It also states the GCC 15.2 test results.
Full details: Linked Issues check
Explanation
Issue #8200 has two coding requirements. Both are implemented in remove.hpp at the reviewed head, compared with the merge base 5d08dcd.
(1) [#8200] No-policy remove_if (iterator/sentinel and range overloads): the constraint now uses hpx::parallel::traits::is_indirect_callable_v<hpx::execution::sequenced_policy, Pred, projected<Proj, Iter>> (and projected_range<Proj, Rng> for the range form). It replaces hpx::is_invocable_v<Pred, iterator_traits::value_type>. This matches the policy overloads and checks the predicate against the projected type.
(2) [#8200] All four remove overloads: the lambda is now [value](auto const& a) and compares value with the projected result that remove_if passes. The default T is now std::remove_cvref_t<std::invoke_result_t<Proj&, std::iter_value_t<Iter>&>> in all four overloads, including the iterator/sentinel and range forms. The previous default, projected<Iter, Proj>::value_type, did not name a type. The current default names the projection result type, as the issue requires.
The incremental diff from the previous reviewed head could not be read. This assessment uses the whole-PR diff from the merge base. The regression tests in remove_if_range.cpp and remove_range.cpp are described only in the PR summary. They were not inspected here. The build and test results were not verified here.
Full details: Out of Scope Changes check
Explanation
The whole-PR diff changes only remove.hpp among the algorithm headers. Those changes affect the constraints, default template arguments, and lambdas of remove_if and remove. These are the overloads named in #8200. The test changes in remove_if_range.cpp and remove_range.cpp, as described in the PR summary, add regression cases for the same member-projection scenario. Tests support this fix. No unrelated behavior change appears in the evidence. The incremental diff could not be read, so the second commit is assessed from the whole-PR diff at the reviewed head.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer TIP This summary will be updated as you push new changes.
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this is right: the predicate now gets what the projection yields, as in the overloads that take a policy, and the tests cover both forms.
The commit is missing the DCO sign-off; could you amend it (git commit --amend -s) and force-push?
Optional, while you are in this file: the default for T in the remove overloads names projected<Iter, Proj>::value_type, but projected takes <Proj, Iter> and has no value_type, so a call that relies on the default (remove(c, {2})) doesn't compile.
…type
The overloads of hpx::ranges::remove_if without an execution policy
required the predicate to be callable with the element type, although
the algorithm calls it with what the projection yields. The four
overloads of hpx::ranges::remove compared the value with a lambda that
took the element type as well. A projection that changes the type,
such as a pointer to a data member, therefore did not compile, while
the same calls are accepted by std::ranges and by the remove_if
overloads that take a policy.
Signed-off-by: Arubik <102335860+ArubikU@users.noreply.github.com>
The default for T in the overloads of hpx::ranges::remove was
projected<Iter, Proj>::value_type. projected takes the projection
first and has no value_type, so the default never named a type. Use
the type the projection yields, spelled as in ranges::count.
Signed-off-by: Arubik <102335860+ArubikU@users.noreply.github.com>
Thanks for the review. Both commits are signed off now.
I added the default for T as a second commit: it now names the type the projection yields, spelled the way ranges::count does it.
One thing I found while testing it: remove(c, {2}) still does not compile with that fix. The call goes through tag_dispatch's operator()(Args&&...), and a braced initializer cannot be deduced for a forwarding pack, so the default for T is never looked at. count and contains get there with their extra operator() overloads ("Supports list-initialized values"). I left that out of this PR to keep it to the projection fix, and can add the same overloads for remove in a follow-up if you want them.
This branch has not been deployed
No deployments
This file contains hidden or 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
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.
Fixes #8200
Proposed Changes
hpx::ranges::remove_ifwithout an execution policy (iterator/sentinel and range) now checks the predicate against the projected type, withis_indirect_callable_v<sequenced_policy, Pred, projected<Proj, Iter>>, the way the overloads that take a policy already do.hpx::ranges::removecompare the value with what the projection yields; the lambda no longer names the element type.remove_if_range.cppandremove_range.cppthat project a struct to anintmember, for the iterator/sentinel and range forms, with and without a policy.Any background context you want to provide?
With a projection that changes the type, such as
&item::id, six of the eight overloads did not compile, whilestd::ranges::remove_if/std::ranges::removeaccept the same calls. Details and a reproducer are in #8200. It is the same kind of problem as #8155 and #8156, in a file those do not touch.Checked with GCC 15.2 (C++20, local runtime): the reproducer from the issue compiles, and
remove_range_testandremove_if_range_testpass with the new cases.Checklist
Not all points below apply to all pull requests.