Debian Codegraph @

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

raw
1 /* { dg-additional-options -std=c++23 } */
2
3 /* C++23 container adaptors in target region.
4 Severely needs additional tests. */
5
6 #include <cstdio>
7 #include <utility>
8 #include <version>
9
10 #if __cpp_lib_flat_map >= 202207L
11 #define ENABLE_FLAT_MAP 1
12 #endif
13 #if __cpp_lib_flat_set >= 202207L
14 #define ENABLE_FLAT_SET 1
15 #endif
16
17 #ifdef ENABLE_FLAT_MAP
18 #include <flat_map>
19 #endif
20 #ifdef ENABLE_FLAT_SET
21 #include <flat_set>
22 #endif
23
24 #include "target-flex-common.h"
25
26 #ifdef ENABLE_FLAT_MAP
27 template<typename K, typename V, typename std::size_t Size>
28 bool test_flat_map(std::pair<K, V> (&arr)[Size])
29 {
30 bool ok;
31 #pragma omp target map(from: ok) map(to: arr[:Size])
32 {
33 bool inner_ok = true;
34 {
35 using flat_map_type = std::flat_map<K, V>;
36 flat_map_type map = {arr, arr + Size};
37
38 VERIFY (!map.empty());
39 for (const auto& element : arr)
40 VERIFY (map.contains(element.first));
41 }
42 end:
43 ok = inner_ok;
44 }
45 return ok;
46 }
47
48 template<typename K, typename V, typename std::size_t Size>
49 bool test_flat_multimap(std::pair<K, V> (&arr)[Size])
50 {
51 bool ok;
52 #pragma omp target map(from: ok) map(to: arr[:Size])
53 {
54 bool inner_ok = true;
55 {
56 using flat_map_type = std::flat_map<K, V>;
57 flat_map_type map = {arr, arr + Size};
58
59 VERIFY (!map.empty());
60 for (const auto& element : arr)
61 VERIFY (map.contains(element.first));
62 }
63 end:
64 ok = inner_ok;
65 }
66 return ok;
67 }
68 #else
69 template<typename K, typename V, typename std::size_t Size>
70 bool test_flat_map(std::pair<K, V> (&arr)[Size]) { return true; }
71
72 template<typename K, typename V, typename std::size_t Size>
73 bool test_flat_multimap(std::pair<K, V> (&arr)[Size]) { return true; }
74 #endif
75
76 #ifdef ENABLE_FLAT_SET
77 template<typename T, typename std::size_t Size>
78 bool test_flat_set(T (&arr)[Size])
79 {
80 bool ok;
81 #pragma omp target map(from: ok) map(to: arr[:Size])
82 {
83 bool inner_ok = true;
84 {
85 using flat_set_type = std::flat_set<T>;
86 flat_set_type set = {arr, arr + Size};
87
88 VERIFY (!set.empty());
89 for (const auto& element : arr)
90 VERIFY (set.contains(element));
91 }
92 end:
93 ok = inner_ok;
94 }
95 return ok;
96 }
97
98 template<typename T, typename std::size_t Size>
99 bool test_flat_multiset(T (&arr)[Size])
100 {
101 bool ok;
102 #pragma omp target map(from: ok) map(to: arr[:Size])
103 {
104 bool inner_ok = true;
105 {
106 using flat_multiset_type = std::flat_multiset<T>;
107 flat_multiset_type multiset = {arr, arr + Size};
108
109 VERIFY (!multiset.empty());
110 for (const auto& element : arr)
111 VERIFY (multiset.contains(element));
112 }
113 end:
114 ok = inner_ok;
115 }
116 return ok;
117 }
118 #else
119 template<typename T, typename std::size_t Size>
120 bool test_flat_set(T (&arr)[Size]) { return true; }
121
122 template<typename T, typename std::size_t Size>
123 bool test_flat_multiset(T (&arr)[Size]) { return true; }
124 #endif
125
126 int main()
127 {
128 int arr[10] = {0,1,2,3,4,5,6,7,8,9};
129 std::pair<int, int> pairs[10] = {{ 1, 2}, { 2, 4}, { 3, 6}, { 4, 8}, { 5, 10},
130 { 6, 12}, { 7, 14}, { 8, 16}, { 9, 18}, {10, 20}};
131
132 return test_flat_set(arr)
133 && test_flat_multiset(arr)
134 && test_flat_map(pairs)
135 && test_flat_multimap(pairs) ? 0 : 1;
136 }