Debian Codegraph @

libgomp/testsuite/libgomp.c++/target-flex-62.C

raw
1 /* { dg-additional-options -std=c++23 } */
2
3 /* std::views stuff. Also tests std::tuple with std::views::zip. */
4
5 #include <algorithm>
6 #include <ranges>
7 #include <span>
8
9 //TODO PR120454 "C++ constexpr vs. OpenMP implicit mapping"
10 #pragma omp declare target(std::ranges::all_of, std::ranges::equal, std::ranges::fold_left, std::views::reverse, std::views::zip)
11
12 #include "target-flex-common.h"
13
14 namespace stdr = std::ranges;
15 namespace stdv = std::views;
16
17 bool f()
18 {
19 const int arr_fwd[8] = {0, 1, 2, 3, 4, 5, 6, 7};
20 const int arr_rev[8] = {7, 6, 5, 4, 3, 2, 1, 0};
21
22 bool ok;
23 #pragma omp target defaultmap(none) map(from: ok) map(to: arr_fwd[:8], arr_rev[:8])
24 {
25 std::span<const int> fwd = {arr_fwd, 8};
26 std::span<const int> rev = {arr_rev, 8};
27 bool inner_ok = true;
28 {
29 VERIFY(stdr::equal(fwd, rev | stdv::reverse));
30 VERIFY(stdr::equal(fwd | stdv::drop(4) | stdv::reverse,
31 rev | stdv::take(4)));
32 for (auto [first, second] : stdv::zip(fwd, rev))
33 VERIFY(first + second == 7);
34 auto plus = [](int a, int b){ return a + b; };
35 auto is_even = [](int v){ return v % 2 == 0; };
36 VERIFY(stdr::fold_left(fwd | stdv::filter(is_even), 0, plus)
37 == 12);
38 VERIFY(stdr::all_of(fwd | stdv::transform([](int v){ return v * 2; }),
39 is_even));
40 }
41 end:
42 ok = inner_ok;
43 }
44 return ok;
45 }
46
47 int main()
48 {
49 return f() ? 0 : 1;
50 }