|
| 1 | +// -*- C++ -*- |
| 2 | +//===----------------------------------------------------------------------===// |
| 3 | +// |
| 4 | +// Copyright (C) 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 | +struct |
| 14 | +{ |
| 15 | + template <std::ranges::random_access_range InRange, std::ranges::random_access_range OutRange, |
| 16 | + typename Pred, typename Proj = std::identity> |
| 17 | + auto operator()(InRange&& r_in, OutRange&& r_out, Pred pred, Proj proj = {}) |
| 18 | + { |
| 19 | + using ret_type = std::ranges::remove_copy_if_result<std::ranges::borrowed_iterator_t<InRange>, |
| 20 | + std::ranges::borrowed_iterator_t<OutRange>>; |
| 21 | + auto in = std::ranges::begin(r_in); |
| 22 | + auto out = std::ranges::begin(r_out); |
| 23 | + std::size_t i = 0, j = 0; |
| 24 | + for(; i < std::ranges::size(r_in); ++i) |
| 25 | + { |
| 26 | + if (!std::invoke(pred, std::invoke(proj, in[i]))) |
| 27 | + { |
| 28 | + if (j < std::ranges::size(r_out)) |
| 29 | + out[j++] = in[i]; |
| 30 | + else |
| 31 | + break; |
| 32 | + } |
| 33 | + } |
| 34 | + return ret_type{in + i, out + j}; |
| 35 | + } |
| 36 | +} remove_copy_if_checker; |
| 37 | +#endif // _ENABLE_STD_RANGES_TESTING |
| 38 | + |
| 39 | +std::int32_t |
| 40 | +main() |
| 41 | +{ |
| 42 | +#if _ENABLE_STD_RANGES_TESTING |
| 43 | + using namespace test_std_ranges; |
| 44 | + namespace dpl_ranges = oneapi::dpl::ranges; |
| 45 | + |
| 46 | + // input generator with a fair chance of repeating the previous value |
| 47 | + auto repeat_sometimes = [](auto i) { |
| 48 | + static decltype(i) last = 0; |
| 49 | + if (i == 0) |
| 50 | + last = 0; // reset |
| 51 | + else if (i%7 > 0 && (last + i - 1)%3 == 0) |
| 52 | + last = i; |
| 53 | + return last; |
| 54 | + }; |
| 55 | + using repeating_gen = decltype(repeat_sometimes); |
| 56 | + auto modulo_3_is_1 = [](int val) { return (val % 3) == 1; }; |
| 57 | + |
| 58 | + test_range_algo<0, int, data_in_out_lim>{239}(dpl_ranges::remove_copy_if, remove_copy_if_checker, pred); |
| 59 | + test_range_algo<1, int, data_in_out_lim>{1471}(dpl_ranges::remove_copy_if, remove_copy_if_checker, select_many); |
| 60 | + test_range_algo<2, int, data_in_out_lim>{}(dpl_ranges::remove_copy_if, remove_copy_if_checker, select_many, proj); |
| 61 | + test_range_algo<3, P2, data_in_out_lim, repeating_gen>{}(dpl_ranges::remove_copy_if, remove_copy_if_checker, modulo_3_is_1, &P2::x); |
| 62 | + test_range_algo<4, P2, data_in_out_lim>{}(dpl_ranges::remove_copy_if, remove_copy_if_checker, pred, &P2::proj); |
| 63 | + test_range_algo<5, int, data_in_out_lim>{big_sz}(dpl_ranges::remove_copy_if, remove_copy_if_checker, pred); |
| 64 | + test_range_algo<6, int, data_in_out_lim, repeating_gen>{big_sz}(dpl_ranges::remove_copy_if, remove_copy_if_checker, select_many); |
| 65 | +#endif // _ENABLE_STD_RANGES_TESTING |
| 66 | + |
| 67 | + return TestUtils::done(_ENABLE_STD_RANGES_TESTING); |
| 68 | +} |
0 commit comments