Skip to content

Fix sentinel return type mismatch in hpx::ranges container algorithm CPOs#7322

Open
aneek22112007-tech wants to merge 3 commits into
TheHPXProject:masterfrom
aneek22112007-tech:fix/sentinel-return-type-container-algos
Open

Fix sentinel return type mismatch in hpx::ranges container algorithm CPOs#7322
aneek22112007-tech wants to merge 3 commits into
TheHPXProject:masterfrom
aneek22112007-tech:fix/sentinel-return-type-container-algos

Conversation

@aneek22112007-tech

Copy link
Copy Markdown
Contributor

Summary

Several hpx::ranges container algorithm CPOs had return type declarations where
the Sent (sentinel) template parameter was silently defaulted to iterator_t<Rng>
when the range overload deduced the sentinel from the range type. This caused
type-safety violations when the container used a sentinel type that differs from
its iterator (a standard-compliant scenario per C++20).

This PR fixes the return types to use subrange_t<iterator_t<Rng>, sentinel_t<Rng>>
as mandated by the C++20 standard.

Affected Algorithms

  • hpx::ranges::rotate
  • hpx::ranges::unique
  • hpx::ranges::partition / hpx::ranges::stable_partition
  • hpx::ranges::remove / hpx::ranges::remove_if
  • hpx::ranges::find_last / hpx::ranges::find_last_if / hpx::ranges::find_last_if_not

Changes

Algorithm Headers

container_algorithms/rotate.hpp, unique.hpp, partition.hpp,
remove.hpp, find.hpp:

  • Changed the container range overloads (tag_fallback_invoke with Rng&& parameter)
    to declare their return type as
    subrange_t<iterator_t<Rng>, sentinel_t<Rng>> instead of
    subrange_t<iterator_t<Rng>> (which collapsed the sentinel to the iterator type).

parallel/algorithms/find.hpp:

  • Fixed find_last, find_last_if, and find_last_if_not parallel dispatch
    implementations to return HPX_MOVE(first) (the iterator) instead of
    HPX_MOVE(last) (the sentinel) when the range is empty, matching the declared
    return type Iter.
  • Added proper async wrapping of the inner Iter result into
    subrange_t<Iter, Sent> for all three parallel range overloads.

Tests

tests/unit/container_algorithms/test_utils.hpp:

  • Added test::test_sentinel_container<Container, IteratorTag> — a lightweight
    range wrapper that exposes test::test_iterator<I, Tag> as its iterator and
    test::sentinel_from_iterator<I> as its sentinel, enabling sentinel-aware
    algorithm tests.

Sentinel regression cases added to each test file:

  • rotate_range.cpp, unique_range.cpp, partition_range.cpp,
    stable_partition_range.cpp, remove_range.cpp, remove_if_range.cpp,
    find_range.cpp

Each test exercises both seq and (where applicable) par execution policies
against a range whose sentinel type differs from its iterator type, verifying
that the returned subrange has the correct begin()/end() values.

Testing

All seven affected test targets built and passed:

rotate_range_test           ✓
unique_range_test           ✓
partition_range_test        ✓
stable_partition_range_test ✓
remove_range_test           ✓
remove_if_range_test        ✓
find_range_test             ✓

Standard Compliance

The corrected signatures match the return types specified in
[range.rotate], [range.unique], [range.partition], [range.remove], and
[range.find.last] of the C++23 working draft.

Notes

  • No public API additions.
  • No behavior changes for iterators whose sentinel type equals their iterator type.
  • No performance impact.

@aneek22112007-tech aneek22112007-tech force-pushed the fix/sentinel-return-type-container-algos branch from f6dc14e to 16a972c Compare June 12, 2026 11:13
@codacy-production

codacy-production Bot commented Jun 12, 2026

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.

@aneek22112007-tech aneek22112007-tech force-pushed the fix/sentinel-return-type-container-algos branch from 16a972c to 227d4ae Compare June 12, 2026 11:14
@StellarBot

Copy link
Copy Markdown
Collaborator

Can one of the admins verify this patch?

Comment thread libs/core/algorithms/include/hpx/parallel/container_algorithms/find.hpp Outdated
Comment thread libs/core/algorithms/include/hpx/parallel/container_algorithms/find.hpp Outdated
Comment thread libs/core/algorithms/include/hpx/parallel/container_algorithms/find.hpp Outdated
@aneek22112007-tech aneek22112007-tech force-pushed the fix/sentinel-return-type-container-algos branch from 5f740ee to c1c4cc9 Compare June 15, 2026 08:22
@hkaiser

hkaiser commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

@aneek22112007-tech please address the compilation issues reported by the CIs. Also, please always have an eye on the CI results yourself.

clang-format is unhappy as well, BTW.

@aneek22112007-tech aneek22112007-tech force-pushed the fix/sentinel-return-type-container-algos branch from d7d6615 to c48ab8a Compare June 19, 2026 06:26
@hkaiser

hkaiser commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

@aneek22112007-tech FWIW, clang-format and inspect are still reporting problems. The changes to one of the tests you did cause compilation issues as well.

@aneek22112007-tech aneek22112007-tech force-pushed the fix/sentinel-return-type-container-algos branch 2 times, most recently from 6137a5d to e159a21 Compare June 21, 2026 09:51
@hkaiser

hkaiser commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

@aneek22112007-tech inspect is unhappy:

/libs/core/algorithms/tests/unit/container_algorithms/find_range.cpp: *I* missing #include (type_traits) for symbol std::is_same_v on line 362

@aneek22112007-tech aneek22112007-tech force-pushed the fix/sentinel-return-type-container-algos branch from 4b0b8ed to 4405e9a Compare June 27, 2026 15:12
@hkaiser

hkaiser commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

@aneek22112007-tech please rebase onto master and resolve the conflicts. Also, the clang-format CI fails and one of the tests doesn't compile..

@aneek22112007-tech aneek22112007-tech force-pushed the fix/sentinel-return-type-container-algos branch from e680cfa to 5488a6b Compare June 29, 2026 17:59
@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: b7ef2a65-ac5a-4043-88dd-e2ea8bf7977f

📥 Commits

Reviewing files that changed from the base of the PR and between d8df77c and 8a99ce8.

📒 Files selected for processing (15)
  • libs/core/algorithms/include/hpx/parallel/algorithms/find.hpp
  • libs/core/algorithms/include/hpx/parallel/container_algorithms/find.hpp
  • libs/core/algorithms/include/hpx/parallel/container_algorithms/partition.hpp
  • libs/core/algorithms/include/hpx/parallel/container_algorithms/remove.hpp
  • libs/core/algorithms/include/hpx/parallel/container_algorithms/rotate.hpp
  • libs/core/algorithms/include/hpx/parallel/container_algorithms/unique.hpp
  • libs/core/algorithms/tests/unit/algorithms/find_tests.hpp
  • libs/core/algorithms/tests/unit/container_algorithms/find_range.cpp
  • libs/core/algorithms/tests/unit/container_algorithms/partition_range.cpp
  • libs/core/algorithms/tests/unit/container_algorithms/remove_if_range.cpp
  • libs/core/algorithms/tests/unit/container_algorithms/remove_range.cpp
  • libs/core/algorithms/tests/unit/container_algorithms/rotate_range.cpp
  • libs/core/algorithms/tests/unit/container_algorithms/stable_partition_range.cpp
  • libs/core/algorithms/tests/unit/container_algorithms/test_utils.hpp
  • libs/core/algorithms/tests/unit/container_algorithms/unique_range.cpp
🚧 Files skipped from review as they are similar to previous changes (12)
  • libs/core/algorithms/tests/unit/algorithms/find_tests.hpp
  • libs/core/algorithms/tests/unit/container_algorithms/remove_range.cpp
  • libs/core/algorithms/include/hpx/parallel/container_algorithms/rotate.hpp
  • libs/core/algorithms/tests/unit/container_algorithms/unique_range.cpp
  • libs/core/algorithms/include/hpx/parallel/container_algorithms/unique.hpp
  • libs/core/algorithms/include/hpx/parallel/container_algorithms/remove.hpp
  • libs/core/algorithms/tests/unit/container_algorithms/find_range.cpp
  • libs/core/algorithms/tests/unit/container_algorithms/stable_partition_range.cpp
  • libs/core/algorithms/tests/unit/container_algorithms/rotate_range.cpp
  • libs/core/algorithms/tests/unit/container_algorithms/partition_range.cpp
  • libs/core/algorithms/include/hpx/parallel/container_algorithms/find.hpp
  • libs/core/algorithms/include/hpx/parallel/algorithms/find.hpp

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes

    • Corrected empty-range results for parallel search algorithms.
    • Improved find_end behavior when searching empty or oversized subsequences.
    • Fixed range algorithm results for sentinel-based ranges.
  • Enhancements

    • Improved compatibility for partition, remove, rotate, unique, and related algorithms with iterator/sentinel ranges.
    • Standardized asynchronous and synchronous result handling for last-match search operations.
  • Tests

    • Added broad coverage for sentinel-based ranges across supported execution policies.

Walkthrough

This PR corrects iterator/sentinel result handling in find-family and range algorithms, centralizes find_last* subrange construction, and adds sentinel-container test coverage for find, partition, remove, rotate, stable partition, and unique.

Changes

Sentinel-aware algorithm results

Layer / File(s) Summary
Find result handling
libs/core/algorithms/include/hpx/parallel/algorithms/find.hpp, libs/core/algorithms/include/hpx/parallel/container_algorithms/find.hpp
Empty-range and find_end edge cases now return sentinel-correct results; find_last* fallbacks share async and synchronous subrange construction.
Range CPO return types
libs/core/algorithms/include/hpx/parallel/container_algorithms/{partition,remove,rotate,unique}.hpp
Range overloads now declare subranges using the input range’s sentinel type.
Sentinel test support and coverage
libs/core/algorithms/tests/unit/container_algorithms/{test_utils,find_range,partition_range,remove_if_range,remove_range,rotate_range,stable_partition_range,unique_range}.cpp
Adds a sentinel-container wrapper and tests sentinel-based algorithms across non-policy, sequential, and parallel modes.
Sender test adjustment
libs/core/algorithms/tests/unit/algorithms/find_tests.hpp
The explicit sender test now dereferences the sync_wait result before extracting the iterator.

Estimated code review effort: 3 (Moderate) | ~25 minutes
Suggested labels: category: tests
Suggested reviewers: hkaiser

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 5.06% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: fixing sentinel return types in hpx::ranges container algorithm CPOs.
Description check ✅ Passed The description is clearly related to the changeset and matches the affected algorithms and test updates.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
libs/core/algorithms/tests/unit/algorithms/find_tests.hpp (1)

76-136: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Guard the sender test wrappers as well find_tests.hpp now hides the sender helpers behind HPX_HAVE_STDEXEC, but libs/core/algorithms/tests/unit/algorithms/find_sender.cpp still defines and calls the wrapper functions unconditionally. Without that macro, this test target will fail to compile.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@libs/core/algorithms/tests/unit/algorithms/find_tests.hpp` around lines 76 -
136, The sender test wrappers in find_tests.hpp are now conditional on
HPX_HAVE_STDEXEC, but find_sender.cpp still defines and calls
test_find_explicit_sender_direct and test_find_explicit_sender unconditionally.
Guard the corresponding definitions and invocation sites in find_sender.cpp with
the same HPX_HAVE_STDEXEC check, or otherwise compile them only when the
sender-related helpers are available. This will keep the test target from
referencing symbols that are absent in non-stDEXEC builds.
🧹 Nitpick comments (1)
libs/core/algorithms/tests/unit/container_algorithms/test_utils.hpp (1)

154-207: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider factoring out common logic between test_container and test_sentinel_container.

Both structs duplicate the constructor, base(), and begin()/cbegin() implementations verbatim; only end()/cend()/the sentinel typedefs differ. A shared base (CRTP or simple composition) would reduce duplication, though this is purely test-utility code with low risk.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@libs/core/algorithms/tests/unit/container_algorithms/test_utils.hpp` around
lines 154 - 207, The test utilities in test_sentinel_container duplicate the
constructor, base(), and begin()/cbegin() logic already present in
test_container. Refactor the shared parts into a common base/helper used by both
test_container and test_sentinel_container, and keep only the differing
end()/cend() and sentinel typedefs in test_sentinel_container so the two types
stay aligned without repeated implementations.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@libs/core/algorithms/include/hpx/parallel/container_algorithms/find.hpp`:
- Around line 2598-2609: The async branch in find’s result handling only chains
with future-based results, but algorithm_result_t<ExPolicy, Iter> can also be
sender-backed for scheduler-executor policies. Update the logic in the
result/subrange return path to either use sender-compatible continuation
chaining for HPX_MOVE(result) or split the branch using
execution_policy_has_scheduler_executor_v<ExPolicy> so sender-backed async
policies are handled correctly while preserving the existing future-based path.

In `@libs/core/algorithms/tests/unit/container_algorithms/find_range.cpp`:
- Around line 380-389: The first find_last_if_not test block computes result and
test_index but never verifies them, so the original unmodified call is not
covered. In the find_last_if_not section of the container_algorithms test, add
an assertion for the initial hpx::ranges::find_last_if_not(c, pred) result using
the existing iterator/base_iterator expectations, and either use test_index in
that check or remove it if unnecessary; keep the later result2 assertion for the
mutated c.base().back() case.

---

Outside diff comments:
In `@libs/core/algorithms/tests/unit/algorithms/find_tests.hpp`:
- Around line 76-136: The sender test wrappers in find_tests.hpp are now
conditional on HPX_HAVE_STDEXEC, but find_sender.cpp still defines and calls
test_find_explicit_sender_direct and test_find_explicit_sender unconditionally.
Guard the corresponding definitions and invocation sites in find_sender.cpp with
the same HPX_HAVE_STDEXEC check, or otherwise compile them only when the
sender-related helpers are available. This will keep the test target from
referencing symbols that are absent in non-stDEXEC builds.

---

Nitpick comments:
In `@libs/core/algorithms/tests/unit/container_algorithms/test_utils.hpp`:
- Around line 154-207: The test utilities in test_sentinel_container duplicate
the constructor, base(), and begin()/cbegin() logic already present in
test_container. Refactor the shared parts into a common base/helper used by both
test_container and test_sentinel_container, and keep only the differing
end()/cend() and sentinel typedefs in test_sentinel_container so the two types
stay aligned without repeated implementations.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 414753ed-7ef9-4446-a9dc-4de3938220b3

📥 Commits

Reviewing files that changed from the base of the PR and between 82e12da and b8dc74d.

📒 Files selected for processing (54)
  • libs/core/algorithms/include/hpx/parallel/algorithms/find.hpp
  • libs/core/algorithms/include/hpx/parallel/container_algorithms/find.hpp
  • libs/core/algorithms/include/hpx/parallel/container_algorithms/iota.hpp
  • libs/core/algorithms/include/hpx/parallel/container_algorithms/is_partitioned.hpp
  • libs/core/algorithms/include/hpx/parallel/container_algorithms/partition.hpp
  • libs/core/algorithms/include/hpx/parallel/container_algorithms/remove.hpp
  • libs/core/algorithms/include/hpx/parallel/container_algorithms/rotate.hpp
  • libs/core/algorithms/include/hpx/parallel/container_algorithms/unique.hpp
  • libs/core/algorithms/tests/unit/algorithms/adjacentdifference_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/adjacentfind_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/all_of_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/any_of_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/count_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/countif_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/ends_with_sender.cpp
  • libs/core/algorithms/tests/unit/algorithms/equal_binary_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/equal_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/find_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/findend_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/findfirstof_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/findif_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/findifnot_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/foreach_sender.cpp
  • libs/core/algorithms/tests/unit/algorithms/foreach_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/includes_sender.cpp
  • libs/core/algorithms/tests/unit/algorithms/is_heap_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/is_partitioned_sender.cpp
  • libs/core/algorithms/tests/unit/algorithms/is_sorted_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/is_sorted_until_sender.cpp
  • libs/core/algorithms/tests/unit/algorithms/lexicographical_compare_sender.cpp
  • libs/core/algorithms/tests/unit/algorithms/max_element_sender.cpp
  • libs/core/algorithms/tests/unit/algorithms/min_element_sender.cpp
  • libs/core/algorithms/tests/unit/algorithms/minmax_element_sender.cpp
  • libs/core/algorithms/tests/unit/algorithms/mismatch_binary_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/mismatch_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/none_of_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/reduce_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/remove_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/search_sender.cpp
  • libs/core/algorithms/tests/unit/algorithms/starts_with_sender.cpp
  • libs/core/algorithms/tests/unit/algorithms/transform_binary2_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/transform_binary_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/transform_reduce_binary_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/transform_reduce_sender.cpp
  • libs/core/algorithms/tests/unit/algorithms/transform_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/unique_tests.hpp
  • libs/core/algorithms/tests/unit/container_algorithms/find_range.cpp
  • libs/core/algorithms/tests/unit/container_algorithms/partition_range.cpp
  • libs/core/algorithms/tests/unit/container_algorithms/remove_if_range.cpp
  • libs/core/algorithms/tests/unit/container_algorithms/remove_range.cpp
  • libs/core/algorithms/tests/unit/container_algorithms/rotate_range.cpp
  • libs/core/algorithms/tests/unit/container_algorithms/stable_partition_range.cpp
  • libs/core/algorithms/tests/unit/container_algorithms/test_utils.hpp
  • libs/core/algorithms/tests/unit/container_algorithms/unique_range.cpp

Comment thread libs/core/algorithms/tests/unit/container_algorithms/find_range.cpp
@aneek22112007-tech aneek22112007-tech force-pushed the fix/sentinel-return-type-container-algos branch from 70476f5 to 2d07e86 Compare July 6, 2026 16:02

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
libs/core/algorithms/tests/unit/algorithms/filln_tests.hpp (1)

73-103: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Guard filln_sender.cpp behind HPX_HAVE_STDEXEC. filln_tests.hpp is already protected, but libs/core/algorithms/tests/unit/algorithms/filln_sender.cpp is still added unconditionally in libs/core/algorithms/tests/unit/algorithms/CMakeLists.txt, so non-HPX_HAVE_STDEXEC builds will still try to instantiate these sender tests and fail.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@libs/core/algorithms/tests/unit/algorithms/filln_tests.hpp` around lines 73 -
103, Guard the sender test target behind HPX_HAVE_STDEXEC in the algorithms test
CMake setup, because filln_tests.hpp is already conditional but filln_sender.cpp
is still always added and will break non-stdexec builds. Update the logic in the
CMakeLists for the algorithms unit tests so the filln_sender.cpp source is only
included when HPX_HAVE_STDEXEC is enabled, matching the existing `#if`
defined(HPX_HAVE_STDEXEC) protection around test_fill_n_sender.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@libs/core/algorithms/tests/unit/algorithms/filln_tests.hpp`:
- Around line 73-103: Guard the sender test target behind HPX_HAVE_STDEXEC in
the algorithms test CMake setup, because filln_tests.hpp is already conditional
but filln_sender.cpp is still always added and will break non-stdexec builds.
Update the logic in the CMakeLists for the algorithms unit tests so the
filln_sender.cpp source is only included when HPX_HAVE_STDEXEC is enabled,
matching the existing `#if` defined(HPX_HAVE_STDEXEC) protection around
test_fill_n_sender.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 3c8dfb30-6383-46ef-b761-99b99f1738a9

📥 Commits

Reviewing files that changed from the base of the PR and between b8dc74d and 70476f5.

📒 Files selected for processing (36)
  • libs/core/algorithms/tests/unit/algorithms/adjacentdifference_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/adjacentfind_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/all_of_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/any_of_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/copy_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/copyn_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/count_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/countif_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/destroy_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/equal_binary_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/equal_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/fill_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/filln_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/findend_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/findfirstof_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/findif_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/findifnot_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/foreach_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/generate_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/generaten_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/is_heap_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/is_sorted_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/mismatch_binary_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/mismatch_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/none_of_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/reduce_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/remove_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/transform_binary2_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/transform_binary_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/transform_reduce_binary_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/transform_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/uninitialized_copy_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/uninitialized_default_construct_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/uninitialized_move_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/uninitialized_value_construct_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/unique_tests.hpp
🚧 Files skipped from review as they are similar to previous changes (16)
  • libs/core/algorithms/tests/unit/algorithms/findifnot_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/transform_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/countif_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/all_of_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/is_sorted_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/any_of_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/transform_binary_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/adjacentfind_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/findfirstof_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/unique_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/reduce_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/adjacentdifference_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/equal_binary_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/count_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/is_heap_tests.hpp
  • libs/core/algorithms/tests/unit/algorithms/equal_tests.hpp

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

Please address the AI generated comments as well.

Comment thread libs/core/algorithms/tests/unit/algorithms/find_tests.hpp Outdated
@hkaiser

hkaiser commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Also, some CIs are failing still. Please have a look.

@aneek22112007-tech aneek22112007-tech force-pushed the fix/sentinel-return-type-container-algos branch from cda9b61 to 858d28a Compare July 9, 2026 15:45
@hkaiser

hkaiser commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Please address the clang-format issues.

@aneek22112007-tech aneek22112007-tech force-pushed the fix/sentinel-return-type-container-algos branch from 0a59c4e to 73c067b Compare July 11, 2026 07:50
@aneek22112007-tech aneek22112007-tech force-pushed the fix/sentinel-return-type-container-algos branch from 73c067b to 16c3a87 Compare July 11, 2026 08:00
@hkaiser

hkaiser commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

…CPOs

Several hpx::ranges container algorithm CPOs had return type declarations where
the sentinel parameter was silently defaulted to iterator_t<Rng> when using
container range overloads. This caused type-safety violations when the container
uses a sentinel type distinct from its iterator type, which is a standard-compliant
scenario per C++20.

This commit fixes the return types to use
subrange_t<iterator_t<Rng>, sentinel_t<Rng>> as required by the C++20/23 standard
for the following algorithms:
  - hpx::ranges::rotate
  - hpx::ranges::unique
  - hpx::ranges::partition / hpx::ranges::stable_partition
  - hpx::ranges::remove / hpx::ranges::remove_if
  - hpx::ranges::find_last / hpx::ranges::find_last_if / hpx::ranges::find_last_if_not

For find_last algorithms specifically:
  - Fixed parallel dispatch implementations to return HPX_MOVE(first) instead of
    HPX_MOVE(last) when the range is empty (last has sentinel type, return type
    expects iterator type)
  - Added proper async wrapping of the inner Iter result into subrange_t<Iter, Sent>
    for all three parallel range overloads

A reusable test::test_sentinel_container<Container, IteratorTag> helper is added
to test_utils.hpp to enable sentinel-aware algorithm tests. Sentinel regression
test cases are added to all seven affected test files and verified to pass.

Signed-off-by: Aneek22112007 <das.aneek007@gmail.com>
- Fix stdexec guards in find_tests.hpp
- Fix return type mismatch in non-policy overloads
- Apply clang-format-20 to all changed files

Signed-off-by: Aneek22112007 <das.aneek007@gmail.com>
Signed-off-by: Aneek22112007 <das.aneek007@gmail.com>
@aneek22112007-tech aneek22112007-tech force-pushed the fix/sentinel-return-type-container-algos branch from d8df77c to 8a99ce8 Compare July 12, 2026 16:20
@aneek22112007-tech

Copy link
Copy Markdown
Contributor Author

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.

3 participants