Skip to content

Apply the predicate of ranges::remove_if and remove to the projected type - #8201

Open
ArubikU wants to merge 2 commits into
TheHPXProject:masterfrom
ArubikU:ranges-remove-projection
Open

ArubikU wants to merge 2 commits into
TheHPXProject:masterfrom
ArubikU:ranges-remove-projection

Conversation

@ArubikU

@ArubikU ArubikU commented Nov 23, 2026

Copy link
Copy Markdown

Fixes #8200

Proposed Changes

  • 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.

@ArubikU
ArubikU requested a review from hkaiser as a code owner November 23, 2026 06:28
@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

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.

Changes: Projected removal

Layer / File(s) Summary
Projection-aware algorithm handling
libs/core/algorithms/include/hpx/parallel/container_algorithms/remove.hpp
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.
Projection regression tests
libs/core/algorithms/tests/unit/container_algorithms/remove_if_range.cpp, libs/core/algorithms/tests/unit/container_algorithms/remove_range.cpp
Tests use projections that select an item’s id. They check returned subranges and retained IDs across the covered overloads.

Estimated code review effort: 2 (Simple) | ~15 minutes

Change: Bug fix · Severity of issue fixed: Medium

Possibly related PRs

  • 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: Passed 4

Check name Status Explanation
Title check Passed 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 Passed 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 Passed 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 Passed 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.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0f38d5c3-aff9-4230-b609-6d3920e24e81
Commits

Reviewing files that changed from the base of the PR and between 5e8367f and fc55f8b.

Files selected for processing: 1

  • libs/core/algorithms/include/hpx/parallel/container_algorithms/remove.hpp

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

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.

@hkaiser hkaiser left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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>
@ArubikU
ArubikU force-pushed the ranges-remove-projection branch from 5e8367f to fc55f8b Compare November 23, 2026 16:17
@ArubikU

ArubikU commented Nov 23, 2026

Copy link
Copy Markdown
Author

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

hpx::ranges::remove_if and remove do not compile with a projection that changes the value type

2 participants