Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[oneDPL][ranges] An implementation fix for a random access range without operator[] and size() method #1969

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[oneDPL][ranges][tests] coverage enhanced with a random access range …
…without operator[] and size() method:

common test code for the all ranges test cases
MikeDvorskiy committed Dec 23, 2024
commit 48abfdf14284e2f5bf107a1c93f8f730ac91edd0
16 changes: 0 additions & 16 deletions test/parallel_api/ranges/std_ranges_for_each.pass.cpp
Original file line number Diff line number Diff line change
@@ -15,16 +15,6 @@

#include "std_ranges_test.h"

//a random access range, but without operator[] and size() method
struct RangeRA
{
int a[10] = {};
int* begin() { return a; }
int* end() { return a + 10; }
const int* begin() const { return a; }
const int* end() const { return a + 10; }
};

std::int32_t
main()
{
@@ -43,12 +33,6 @@ main()
test_range_algo<2, P2>{}(dpl_ranges::for_each, for_each_checker, f_mutuable, &P2::x);
test_range_algo<3, P2>{}(dpl_ranges::for_each, for_each_checker, f_mutuable, &P2::proj);

#if TEST_DPCPP_BACKEND_PRESENT
//test with a random access range without operator[] and size() method
RangeRA in_range;
dpl_ranges::for_each(dpcpp_policy(), in_range, f);
#endif //TEST_DPCPP_BACKEND_PRESENT

#endif //_ENABLE_STD_RANGES_TESTING

return TestUtils::done(_ENABLE_STD_RANGES_TESTING);
24 changes: 24 additions & 0 deletions test/parallel_api/ranges/std_ranges_test.h
Original file line number Diff line number Diff line change
@@ -144,6 +144,28 @@ template<typename T>
static constexpr
bool is_range<T, std::void_t<decltype(std::declval<T&>().begin())>> = true;

//a random access range, but without operator[] and size() method
template<typename R>
struct RangeRA
{
RangeRA(R r): m_r(r) {}
R m_r;
auto begin() { return m_r.begin(); }
auto end() { return m_r.end(); }
auto begin() const { return m_r.begin(); }
auto end() const { return m_r.end(); }
};

struct __range_ra_fn
{
template<typename R>
RangeRA<R>
operator()(R r)
{
return RangeRA<R>(r);
}
} __range_ra_wr;

template<typename DataType, typename Container, TestDataMode test_mode = data_in>
struct test
{
@@ -536,6 +558,7 @@ struct test_range_algo
test<T, host_vector<T>, mode>{max_n}(host_policies(), algo, checker, subrange_view, std::identity{}, args...);
test<T, host_vector<T>, mode>{max_n}(host_policies(), algo, checker, std::views::all, std::identity{}, args...);
test<T, host_subrange<T>, mode>{max_n}(host_policies(), algo, checker, std::views::all, std::identity{}, args...);
test<T, host_subrange<T>, mode>{max_n}(host_policies(), algo, checker, __range_ra_wr, __range_ra_wr, args...);
#if TEST_CPP20_SPAN_PRESENT
test<T, host_vector<T>, mode>{max_n}(host_policies(), algo, checker, span_view, std::identity{}, args...);
test<T, host_span<T>, mode>{max_n}(host_policies(), algo, checker, std::views::all, std::identity{}, args...);
@@ -551,6 +574,7 @@ struct test_range_algo
{
test<T, usm_vector<T>, mode>{max_n}(dpcpp_policy<call_id + 10>(), algo, checker, subrange_view, subrange_view, args...);
test<T, usm_subrange<T>, mode>{max_n}(dpcpp_policy<call_id + 30>(), algo, checker, std::identity{}, std::identity{}, args...);
test<T, usm_subrange<T>, mode>{max_n}(dpcpp_policy<call_id + 35>(), algo, checker, __range_ra_wr, __range_ra_wr, args...);
#if TEST_CPP20_SPAN_PRESENT
test<T, usm_vector<T>, mode>{max_n}(dpcpp_policy<call_id + 20>(), algo, checker, span_view, subrange_view, args...);
test<T, usm_span<T>, mode>{max_n}(dpcpp_policy<call_id + 40>(), algo, checker, std::identity{}, std::identity{}, args...);