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