Skip to content

Commit

Permalink
[oneDPL][ranges][zip_view][test] LLVM test begin.pass adaptation for …
Browse files Browse the repository at this point in the history
…oneDPL
  • Loading branch information
MikeDvorskiy committed Feb 7, 2025
1 parent cf75150 commit c7412b1
Showing 1 changed file with 18 additions and 21 deletions.
39 changes: 18 additions & 21 deletions test/parallel_api/ranges/range.zip/begin.pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,9 @@
#include <utility>
#include "types.h"

//#include "zip_view_impl.h"
#include <oneapi/dpl/ranges>

namespace std
{
namespace ranges
{
using oneapi::dpl::ranges::zip_view;
}
}
namespace dpl_ranges = oneapi::dpl::ranges;

template <class T>
concept HasConstBegin = requires(const T& ct) { ct.begin(); };
Expand All @@ -54,26 +47,30 @@ struct NoConstBeginView : std::ranges::view_base {
int* end();
};

constexpr bool test() {
template <typename... Types>
using tuple_type = oneapi::dpl::__internal::tuple<Types...>;

int test() {
int buffer[8] = {1, 2, 3, 4, 5, 6, 7, 8};
{
// all underlying iterators should be at the begin position
std::ranges::zip_view v(SizedRandomAccessView{buffer}, std::views::iota(0), std::ranges::single_view(2.));
std::same_as<std::tuple<int&, int, double&>> decltype(auto) val = *v.begin();
dpl_ranges::zip_view v(SizedRandomAccessView{buffer}, std::views::iota(0), std::ranges::single_view(2.));
using value_t = std::ranges::range_value_t<decltype(v)>;
std::same_as<tuple_type<int&, int, double&>> decltype(auto) val = *v.begin();
assert(val == std::make_tuple(1, 0, 2.0));
assert(&(std::get<0>(val)) == &buffer[0]);
}

{
// with empty range
std::ranges::zip_view v(SizedRandomAccessView{buffer}, std::ranges::empty_view<int>());
dpl_ranges::zip_view v(SizedRandomAccessView{buffer}, std::ranges::empty_view<int>());
assert(v.begin() == v.end());
}

{
// underlying ranges all model simple-view
std::ranges::zip_view v(SimpleCommon{buffer}, SimpleCommon{buffer});
static_assert(std::is_same_v<decltype(v.begin()), decltype(std::as_const(v).begin())>);
dpl_ranges::zip_view v(SimpleCommon{buffer}, SimpleCommon{buffer});
static_assert(std::is_same_v<decltype(v.begin()), decltype(std::as_const(v).begin())>);
assert(v.begin() == std::as_const(v).begin());
auto [x, y] = *std::as_const(v).begin();
assert(&x == &buffer[0]);
Expand All @@ -87,8 +84,9 @@ constexpr bool test() {

{
// not all underlying ranges model simple-view
std::ranges::zip_view v(SimpleCommon{buffer}, NonSimpleNonCommon{buffer});
dpl_ranges::zip_view v(SimpleCommon{buffer}, NonSimpleNonCommon{buffer});
static_assert(!std::is_same_v<decltype(v.begin()), decltype(std::as_const(v).begin())>);

assert(v.begin() == std::as_const(v).begin());
auto [x, y] = *std::as_const(v).begin();
assert(&x == &buffer[0]);
Expand All @@ -98,21 +96,20 @@ constexpr bool test() {
static_assert(!HasOnlyConstBegin<View>);
static_assert(!HasOnlyNonConstBegin<View>);
static_assert(HasConstAndNonConstBegin<View>);
return 0;
}

#if 0
{
// underlying const R is not a range
using View = std::ranges::zip_view<SimpleCommon, NoConstBeginView>;
using View = dpl_ranges::zip_view<SimpleCommon, NoConstBeginView>;
static_assert(!HasOnlyConstBegin<View>);
static_assert(HasOnlyNonConstBegin<View>);
static_assert(!HasConstAndNonConstBegin<View>);
}
return true;
#endif
}

int main(int, char**) {
test();
static_assert(test());

return 0;
return test();
}

0 comments on commit c7412b1

Please sign in to comment.