|
| 1 | +// -*- C++ -*- |
| 2 | +//===----------------------------------------------------------------------===// |
| 3 | +// |
| 4 | +// Copyright (C) 2026 UXL Foundation Contributors |
| 5 | +// |
| 6 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 7 | +// |
| 8 | +//===----------------------------------------------------------------------===// |
| 9 | + |
| 10 | +#include "std_ranges_test.h" |
| 11 | + |
| 12 | +#if _ENABLE_STD_RANGES_TESTING |
| 13 | + template<int call_id, typename T, typename DataGen2 = std::identity> |
| 14 | + using launcher = test_std_ranges::test_range_algo<call_id, T, test_std_ranges::data_in_in, |
| 15 | + /*DataGen1*/ std::identity, DataGen2>; |
| 16 | +#if __cpp_lib_ranges_contains >= 202207L |
| 17 | + auto checker = TEST_PREPARE_CALLABLE(std::ranges::contains_subrange); |
| 18 | +#else |
| 19 | + struct { |
| 20 | + |
| 21 | + template<std::ranges::forward_range R1, std::ranges::forward_range R2, typename Pred = std::ranges::equal_to, |
| 22 | + typename Proj1 = std::identity, typename Proj2 = std::identity> |
| 23 | + bool operator()(R1&& r1, R2&& r2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}) |
| 24 | + { |
| 25 | + if (std::ranges::begin(r2) == std::ranges::end(r2)) |
| 26 | + return true; |
| 27 | + auto&& result = std::ranges::search(r1, r2, pred, proj1, proj2); |
| 28 | + return !result.empty(); |
| 29 | + } |
| 30 | + } checker; |
| 31 | +#endif |
| 32 | +#endif |
| 33 | + |
| 34 | +std::int32_t |
| 35 | +main() |
| 36 | +{ |
| 37 | +#if _ENABLE_STD_RANGES_TESTING |
| 38 | + using namespace test_std_ranges; |
| 39 | + namespace dpl_ranges = oneapi::dpl::ranges; |
| 40 | + |
| 41 | + auto lam = [](auto i) { return i + 371; }; |
| 42 | + using data_gen_shifted = decltype(lam); |
| 43 | + |
| 44 | + // Sizes of both sequences will vary in the test, so each call might test both successful and unsuccessful searches |
| 45 | + launcher<0, int>{big_sz}(dpl_ranges::contains_subrange, checker, binary_pred_const); |
| 46 | + launcher<1, int>{}(dpl_ranges::contains_subrange, checker); |
| 47 | + launcher<2, int>{}(dpl_ranges::contains_subrange, checker, binary_pred, dpl::identity{}); |
| 48 | + launcher<3, int, data_gen_shifted>{big_sz}(dpl_ranges::contains_subrange, checker, binary_pred, proj, proj); |
| 49 | + launcher<4, P3, data_gen_shifted>{}(dpl_ranges::contains_subrange, checker, binary_pred_const, &P3::x, &P3::proj); |
| 50 | + launcher<5, P3>{}(dpl_ranges::contains_subrange, checker, std::equal_to<>{}, &P3::proj, &P3::y); |
| 51 | +#endif //_ENABLE_STD_RANGES_TESTING |
| 52 | + |
| 53 | + return TestUtils::done(_ENABLE_STD_RANGES_TESTING); |
| 54 | +} |
0 commit comments