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