Skip to content

Commit 470650b

Browse files
committed
tests: add regression test for proxy-reference support in find algorithms
Signed-off-by: ArivoliR <arivoli2005@gmail.com>
1 parent afcbb5b commit 470650b

2 files changed

Lines changed: 57 additions & 0 deletions

File tree

libs/core/algorithms/tests/regressions/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ set(tests
88
count_3646
99
fill_executor_5016
1010
findfirstof_more_searched_for
11+
find_proxy_support
1112
for_each_annotated_function
1213
for_each_on_main_thread
1314
for_loop_2281
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Copyright (c) 2025 Arivoli Ramamoorthy
2+
//
3+
// SPDX-License-Identifier: BSL-1.0
4+
// Distributed under the Boost Software License, Version 1.0.
5+
// (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6+
7+
// Regression test for Issue #6719
8+
// Ensures that the find-family algorithms correctly handle proxy-reference
9+
10+
#include <hpx/algorithm.hpp>
11+
#include <hpx/executors/execution_policy.hpp>
12+
#include <hpx/init.hpp>
13+
#include <hpx/modules/testing.hpp>
14+
15+
#include <vector>
16+
17+
void find_proxy_reference_test()
18+
{
19+
std::vector<bool> v = {false, true, false, true};
20+
21+
// Sequential policy
22+
auto it_seq = hpx::find(hpx::execution::seq, v.begin(), v.end(), true);
23+
HPX_TEST(it_seq != v.end());
24+
HPX_TEST_EQ(std::distance(v.begin(), it_seq), 1);
25+
26+
// Parallel policy
27+
auto it_par = hpx::find(hpx::execution::par, v.begin(), v.end(), false);
28+
HPX_TEST(it_par != v.end());
29+
HPX_TEST_EQ(std::distance(v.begin(), it_par), 0);
30+
31+
// find_if
32+
auto it_if = hpx::find_if(
33+
hpx::execution::seq, v.begin(), v.end(), [](bool x) { return x; });
34+
HPX_TEST(it_if != v.end());
35+
HPX_TEST_EQ(std::distance(v.begin(), it_if), 1);
36+
37+
// find_if_not
38+
auto it_not = hpx::find_if_not(
39+
hpx::execution::par, v.begin(), v.end(), [](bool x) { return x; });
40+
HPX_TEST(it_not != v.end());
41+
HPX_TEST_EQ(std::distance(v.begin(), it_not), 0);
42+
}
43+
44+
int hpx_main()
45+
{
46+
find_proxy_reference_test();
47+
return hpx::local::finalize();
48+
}
49+
50+
int main(int argc, char* argv[])
51+
{
52+
HPX_TEST_EQ_MSG(hpx::local::init(hpx_main, argc, argv), 0,
53+
"HPX main exited with non-zero status");
54+
55+
return hpx::util::report_errors();
56+
}

0 commit comments

Comments
 (0)