-
Notifications
You must be signed in to change notification settings - Fork 1
/
trait_test.cpp
348 lines (294 loc) · 20.9 KB
/
trait_test.cpp
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
#include "internal/doctest.h"
#include <array>
#include <complex>
#include <cstdint>
#include <deque>
#include <forward_list>
#include <list>
#include <map>
#include <set>
#include <span>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <valarray>
#include <vector>
#define MPI_USE_RELAXED_TRAITS
#include <mpi/all.hpp>
struct aggregate
{
std::int32_t x {};
std::array<std::int32_t, 3> y {};
};
struct non_aggregate : aggregate
{
std::string z {};
};
struct nested_aggregate
{
std::int32_t x {};
aggregate y {};
};
struct nested_non_aggregate
{
std::int32_t x {};
non_aggregate y {};
};
enum class enum_type { x, y, z };
using non_compliant_type = std::string;
using arithmetic_compliant_type = float;
using enum_compliant_type = enum_type;
using complex_compliant_type = std::complex<float>;
using complex_non_compliant_type = std::complex<std::uint64_t>;
using static_c_array_compliant_type = float[4];
using static_c_array_compliant_type_2d = float[4][4];
using static_c_array_compliant_type_3d = float[4][4][4];
using static_c_array_compliant_type_4d = float[4][4][4][4];
using static_c_array_non_compliant_type = std::string[4];
using static_c_array_non_compliant_type_2d = std::string[4][4];
using static_c_array_non_compliant_type_3d = std::string[4][4][4];
using static_c_array_non_compliant_type_4d = std::string[4][4][4];
using dynamic_c_array_non_compliant_type = float[ ];
using dynamic_c_array_non_compliant_type_2d = float[ ][4];
using dynamic_c_array_non_compliant_type_3d = float[ ][4][4];
using dynamic_c_array_non_compliant_type_4d = float[ ][4][4][4];
using dynamic_c_array_non_compliant_type_2 = std::string[ ];
using dynamic_c_array_non_compliant_type_2_2d = std::string[ ][4];
using dynamic_c_array_non_compliant_type_2_3d = std::string[ ][4][4];
using dynamic_c_array_non_compliant_type_2_4d = std::string[ ][4][4];
using array_compliant_type = std::array<float, 4>;
using array_compliant_type_2d = std::array<std::array<float, 4>, 4>;
using array_compliant_type_3d = std::array<std::array<std::array<float, 4>, 4>, 4>;
using array_compliant_type_4d = std::array<std::array<std::array<std::array<float, 4>, 4>, 4>, 4>;
using array_non_compliant_type = std::array<std::string, 4>;
using array_non_compliant_type_2d = std::array<std::array<std::string, 4>, 4>;
using array_non_compliant_type_3d = std::array<std::array<std::array<std::string, 4>, 4>, 4>;
using array_non_compliant_type_4d = std::array<std::array<std::array<std::array<std::string, 4>, 4>, 4>, 4>;
using pair_compliant_type = std::pair<std::int32_t, std::int32_t>;
using pair_compliant_type_2d = std::pair<std::int32_t, std::pair<std::int32_t, std::int32_t>>;
using pair_non_compliant_type = std::pair<std::int32_t, std::string >;
using pair_non_compliant_type_2d = std::pair<std::int32_t, std::pair<std::int32_t, std::string>>;
using tuple_compliant_type = std::tuple<std::int32_t, std::int32_t>;
using tuple_compliant_type_2d = std::tuple<std::int32_t, std::tuple<std::int32_t, std::int32_t>>;
using tuple_non_compliant_type = std::tuple<std::int32_t, std::string >;
using tuple_non_compliant_type_2d = std::tuple<std::int32_t, std::tuple<std::int32_t, std::string>>;
using aggregate_compliant_type = aggregate;
using aggregate_compliant_type_2d = nested_aggregate;
using aggregate_non_compliant_type = non_aggregate;
using aggregate_non_compliant_type_2d = nested_non_aggregate;
using map_compliant_type = std::map<std::int32_t, std::int32_t>;
using map_compliant_type_2 = std::map<std::int32_t, aggregate>;
using map_non_compliant_type = std::map<std::int32_t, std::string>;
using map_non_compliant_type_2 = std::map<std::int32_t, non_aggregate>;
using unordered_map_compliant_type = std::unordered_map<std::int32_t, std::int32_t>;
using unordered_map_compliant_type_2 = std::unordered_map<std::int32_t, aggregate>;
using unordered_map_non_compliant_type = std::unordered_map<std::int32_t, std::string>;
using unordered_map_non_compliant_type_2 = std::unordered_map<std::int32_t, non_aggregate>;
using set_compliant_type = std::set<std::int32_t>;
using set_compliant_type_2 = std::set<aggregate>;
using set_non_compliant_type = std::set<std::string>;
using set_non_compliant_type_2 = std::set<non_aggregate>;
using unordered_set_compliant_type = std::unordered_set<std::int32_t>;
using unordered_set_compliant_type_2 = std::unordered_set<aggregate>;
using unordered_set_non_compliant_type = std::unordered_set<std::string>;
using unordered_set_non_compliant_type_2 = std::unordered_set<non_aggregate>;
using deque_compliant_type = std::deque<std::int32_t>;
using deque_compliant_type_2 = std::deque<aggregate>;
using deque_non_compliant_type = std::deque<std::string>;
using deque_non_compliant_type_2 = std::deque<non_aggregate>;
using deque_compliant_type_2d = std::deque<std::deque<std::int32_t>>;
using deque_non_compliant_type_2d = std::deque<std::deque<std::string>>;
using forward_list_compliant_type = std::forward_list<std::int32_t>;
using forward_list_compliant_type_2 = std::forward_list<aggregate>;
using forward_list_non_compliant_type = std::forward_list<std::string>;
using forward_list_non_compliant_type_2 = std::forward_list<non_aggregate>;
using forward_list_compliant_type_2d = std::forward_list<std::forward_list<std::int32_t>>;
using forward_list_non_compliant_type_2d = std::forward_list<std::forward_list<std::string>>;
using list_compliant_type = std::list<std::int32_t>;
using list_compliant_type_2 = std::list<aggregate>;
using list_non_compliant_type = std::list<std::string>;
using list_non_compliant_type_2 = std::list<non_aggregate>;
using list_compliant_type_2d = std::list<std::list<std::int32_t>>;
using list_non_compliant_type_2d = std::list<std::list<std::string>>;
using static_span_compliant_type = std::span<float , 4>;
using static_span_non_compliant_type = std::span<std::string, 4>;
using static_span_non_compliant_type_2d = std::span<std::span<float , 4>, 4>;
using static_span_non_compliant_type_2_2d = std::span<std::span<std::string, 4>, 4>;
using dynamic_span_compliant_type = std::span<float>;
using dynamic_span_non_compliant_type_2d = std::span<std::string>;
using valarray_compliant_type = std::valarray<std::int32_t>;
using valarray_compliant_type_2 = std::valarray<aggregate>;
using valarray_non_compliant_type = std::valarray<std::string>;
using valarray_non_compliant_type_2 = std::valarray<non_aggregate>;
using valarray_compliant_type_2d = std::valarray<std::valarray<std::int32_t>>;
using valarray_non_compliant_type_2d = std::valarray<std::valarray<std::string>>;
using vector_compliant_type = std::vector<std::int32_t>;
using vector_compliant_type_2 = std::vector<aggregate>;
using vector_non_compliant_type = std::vector<std::string>;
using vector_non_compliant_type_2 = std::vector<non_aggregate>;
using vector_compliant_type_2d = std::vector<std::vector<std::int32_t>>;
using vector_non_compliant_type_2d = std::vector<std::vector<std::string>>;
TEST_CASE("Trait Test")
{
mpi::environment environment;
REQUIRE(!mpi::is_compliant_v<non_compliant_type >);
REQUIRE( mpi::is_compliant_v<arithmetic_compliant_type >);
REQUIRE( mpi::is_compliant_v<enum_compliant_type >);
REQUIRE( mpi::is_compliant_v<complex_compliant_type >);
REQUIRE(!mpi::is_compliant_v<complex_non_compliant_type >);
REQUIRE( mpi::is_compliant_v<static_c_array_compliant_type >);
REQUIRE( mpi::is_compliant_v<static_c_array_compliant_type_2d >);
REQUIRE( mpi::is_compliant_v<static_c_array_compliant_type_3d >);
REQUIRE( mpi::is_compliant_v<static_c_array_compliant_type_4d >);
REQUIRE(!mpi::is_compliant_v<static_c_array_non_compliant_type >);
REQUIRE(!mpi::is_compliant_v<static_c_array_non_compliant_type_2d >);
REQUIRE(!mpi::is_compliant_v<static_c_array_non_compliant_type_3d >);
REQUIRE(!mpi::is_compliant_v<static_c_array_non_compliant_type_4d >);
REQUIRE(!mpi::is_compliant_v<dynamic_c_array_non_compliant_type >);
REQUIRE(!mpi::is_compliant_v<dynamic_c_array_non_compliant_type_2d >);
REQUIRE(!mpi::is_compliant_v<dynamic_c_array_non_compliant_type_3d >);
REQUIRE(!mpi::is_compliant_v<dynamic_c_array_non_compliant_type_4d >);
REQUIRE(!mpi::is_compliant_v<dynamic_c_array_non_compliant_type_2 >);
REQUIRE(!mpi::is_compliant_v<dynamic_c_array_non_compliant_type_2_2d>);
REQUIRE(!mpi::is_compliant_v<dynamic_c_array_non_compliant_type_2_3d>);
REQUIRE(!mpi::is_compliant_v<dynamic_c_array_non_compliant_type_2_4d>);
REQUIRE( mpi::is_compliant_v<array_compliant_type >);
REQUIRE( mpi::is_compliant_v<array_compliant_type_2d >);
REQUIRE( mpi::is_compliant_v<array_compliant_type_3d >);
REQUIRE( mpi::is_compliant_v<array_compliant_type_4d >);
REQUIRE(!mpi::is_compliant_v<array_non_compliant_type >);
REQUIRE(!mpi::is_compliant_v<array_non_compliant_type_2d >);
REQUIRE(!mpi::is_compliant_v<array_non_compliant_type_3d >);
REQUIRE(!mpi::is_compliant_v<array_non_compliant_type_4d >);
REQUIRE( mpi::is_compliant_v<pair_compliant_type >);
REQUIRE( mpi::is_compliant_v<pair_compliant_type_2d >);
REQUIRE(!mpi::is_compliant_v<pair_non_compliant_type >);
REQUIRE(!mpi::is_compliant_v<pair_non_compliant_type_2d >);
REQUIRE( mpi::is_compliant_v<tuple_compliant_type >);
REQUIRE( mpi::is_compliant_v<tuple_compliant_type_2d >);
REQUIRE(!mpi::is_compliant_v<tuple_non_compliant_type >);
REQUIRE(!mpi::is_compliant_v<tuple_non_compliant_type_2d >);
REQUIRE( mpi::is_compliant_v<aggregate_compliant_type >);
REQUIRE( mpi::is_compliant_v<aggregate_compliant_type_2d >);
#ifdef MPI_USE_RELAXED_TRAITS // It is not possible to detect if the inner types are compliant with relaxed traits.
REQUIRE( mpi::is_compliant_v<aggregate_non_compliant_type >);
REQUIRE( mpi::is_compliant_v<aggregate_non_compliant_type_2d >);
#else
REQUIRE(!mpi::is_compliant_v<aggregate_non_compliant_type >);
REQUIRE(!mpi::is_compliant_v<aggregate_non_compliant_type_2d >);
#endif
REQUIRE(!mpi::is_compliant_v<map_compliant_type >);
REQUIRE(!mpi::is_compliant_v<map_compliant_type_2 >);
REQUIRE(!mpi::is_compliant_v<map_non_compliant_type >);
REQUIRE(!mpi::is_compliant_v<map_non_compliant_type_2 >);
REQUIRE(!mpi::is_compliant_v<unordered_map_compliant_type >);
REQUIRE(!mpi::is_compliant_v<unordered_map_compliant_type_2 >);
REQUIRE(!mpi::is_compliant_v<unordered_map_non_compliant_type >);
REQUIRE(!mpi::is_compliant_v<unordered_map_non_compliant_type_2 >);
REQUIRE(!mpi::is_compliant_v<set_compliant_type >);
REQUIRE(!mpi::is_compliant_v<set_compliant_type_2 >);
REQUIRE(!mpi::is_compliant_v<set_non_compliant_type >);
REQUIRE(!mpi::is_compliant_v<set_non_compliant_type_2 >);
REQUIRE(!mpi::is_compliant_v<unordered_set_compliant_type >);
REQUIRE(!mpi::is_compliant_v<unordered_set_compliant_type_2 >);
REQUIRE(!mpi::is_compliant_v<unordered_set_non_compliant_type >);
REQUIRE(!mpi::is_compliant_v<unordered_set_non_compliant_type_2 >);
REQUIRE(!mpi::is_compliant_v<deque_compliant_type >);
REQUIRE(!mpi::is_compliant_v<deque_compliant_type_2 >);
REQUIRE(!mpi::is_compliant_v<deque_non_compliant_type >);
REQUIRE(!mpi::is_compliant_v<deque_non_compliant_type_2 >);
REQUIRE(!mpi::is_compliant_v<deque_compliant_type_2d >);
REQUIRE(!mpi::is_compliant_v<deque_non_compliant_type_2d >);
REQUIRE(!mpi::is_compliant_v<forward_list_compliant_type >);
REQUIRE(!mpi::is_compliant_v<forward_list_compliant_type_2 >);
REQUIRE(!mpi::is_compliant_v<forward_list_non_compliant_type >);
REQUIRE(!mpi::is_compliant_v<forward_list_non_compliant_type_2 >);
REQUIRE(!mpi::is_compliant_v<forward_list_compliant_type_2d >);
REQUIRE(!mpi::is_compliant_v<forward_list_non_compliant_type_2d >);
REQUIRE(!mpi::is_compliant_v<list_compliant_type >);
REQUIRE(!mpi::is_compliant_v<list_compliant_type_2 >);
REQUIRE(!mpi::is_compliant_v<list_non_compliant_type >);
REQUIRE(!mpi::is_compliant_v<list_non_compliant_type_2 >);
REQUIRE(!mpi::is_compliant_v<list_compliant_type_2d >);
REQUIRE(!mpi::is_compliant_v<list_non_compliant_type_2d >);
REQUIRE(!mpi::is_compliant_v<static_span_compliant_type >);
REQUIRE(!mpi::is_compliant_v<static_span_non_compliant_type >);
REQUIRE(!mpi::is_compliant_v<static_span_non_compliant_type_2d >);
REQUIRE(!mpi::is_compliant_v<static_span_non_compliant_type_2_2d >);
REQUIRE(!mpi::is_compliant_v<dynamic_span_compliant_type >);
REQUIRE(!mpi::is_compliant_v<dynamic_span_non_compliant_type_2d >);
REQUIRE(!mpi::is_compliant_v<valarray_compliant_type >);
REQUIRE(!mpi::is_compliant_v<valarray_compliant_type_2 >);
REQUIRE(!mpi::is_compliant_v<valarray_non_compliant_type >);
REQUIRE(!mpi::is_compliant_v<valarray_non_compliant_type_2 >);
REQUIRE(!mpi::is_compliant_v<valarray_compliant_type_2d >);
REQUIRE(!mpi::is_compliant_v<valarray_non_compliant_type_2d >);
REQUIRE(!mpi::is_compliant_v<vector_compliant_type >);
REQUIRE(!mpi::is_compliant_v<vector_compliant_type_2 >);
REQUIRE(!mpi::is_compliant_v<vector_non_compliant_type >);
REQUIRE(!mpi::is_compliant_v<vector_non_compliant_type_2 >);
REQUIRE(!mpi::is_compliant_v<vector_compliant_type_2d >);
REQUIRE(!mpi::is_compliant_v<vector_non_compliant_type_2d >);
REQUIRE(!mpi::is_compliant_contiguous_sequential_container_v<map_compliant_type >);
REQUIRE(!mpi::is_compliant_contiguous_sequential_container_v<map_compliant_type_2 >);
REQUIRE(!mpi::is_compliant_contiguous_sequential_container_v<map_non_compliant_type >);
REQUIRE(!mpi::is_compliant_contiguous_sequential_container_v<map_non_compliant_type_2 >);
REQUIRE(!mpi::is_compliant_contiguous_sequential_container_v<unordered_map_compliant_type >);
REQUIRE(!mpi::is_compliant_contiguous_sequential_container_v<unordered_map_compliant_type_2 >);
REQUIRE(!mpi::is_compliant_contiguous_sequential_container_v<unordered_map_non_compliant_type >);
REQUIRE(!mpi::is_compliant_contiguous_sequential_container_v<unordered_map_non_compliant_type_2 >);
REQUIRE(!mpi::is_compliant_contiguous_sequential_container_v<set_compliant_type >);
REQUIRE(!mpi::is_compliant_contiguous_sequential_container_v<set_compliant_type_2 >);
REQUIRE(!mpi::is_compliant_contiguous_sequential_container_v<set_non_compliant_type >);
REQUIRE(!mpi::is_compliant_contiguous_sequential_container_v<set_non_compliant_type_2 >);
REQUIRE(!mpi::is_compliant_contiguous_sequential_container_v<unordered_set_compliant_type >);
REQUIRE(!mpi::is_compliant_contiguous_sequential_container_v<unordered_set_compliant_type_2 >);
REQUIRE(!mpi::is_compliant_contiguous_sequential_container_v<unordered_set_non_compliant_type >);
REQUIRE(!mpi::is_compliant_contiguous_sequential_container_v<unordered_set_non_compliant_type_2 >);
REQUIRE(!mpi::is_compliant_contiguous_sequential_container_v<deque_compliant_type >);
REQUIRE(!mpi::is_compliant_contiguous_sequential_container_v<deque_compliant_type_2 >);
REQUIRE(!mpi::is_compliant_contiguous_sequential_container_v<deque_non_compliant_type >);
REQUIRE(!mpi::is_compliant_contiguous_sequential_container_v<deque_non_compliant_type_2 >);
REQUIRE(!mpi::is_compliant_contiguous_sequential_container_v<deque_compliant_type_2d >);
REQUIRE(!mpi::is_compliant_contiguous_sequential_container_v<deque_non_compliant_type_2d >);
REQUIRE(!mpi::is_compliant_contiguous_sequential_container_v<forward_list_compliant_type >);
REQUIRE(!mpi::is_compliant_contiguous_sequential_container_v<forward_list_compliant_type_2 >);
REQUIRE(!mpi::is_compliant_contiguous_sequential_container_v<forward_list_non_compliant_type >);
REQUIRE(!mpi::is_compliant_contiguous_sequential_container_v<forward_list_non_compliant_type_2 >);
REQUIRE(!mpi::is_compliant_contiguous_sequential_container_v<forward_list_compliant_type_2d >);
REQUIRE(!mpi::is_compliant_contiguous_sequential_container_v<forward_list_non_compliant_type_2d >);
REQUIRE(!mpi::is_compliant_contiguous_sequential_container_v<list_compliant_type >);
REQUIRE(!mpi::is_compliant_contiguous_sequential_container_v<list_compliant_type_2 >);
REQUIRE(!mpi::is_compliant_contiguous_sequential_container_v<list_non_compliant_type >);
REQUIRE(!mpi::is_compliant_contiguous_sequential_container_v<list_non_compliant_type_2 >);
REQUIRE(!mpi::is_compliant_contiguous_sequential_container_v<list_compliant_type_2d >);
REQUIRE(!mpi::is_compliant_contiguous_sequential_container_v<list_non_compliant_type_2d >);
REQUIRE( mpi::is_compliant_contiguous_sequential_container_v<static_span_compliant_type >);
REQUIRE(!mpi::is_compliant_contiguous_sequential_container_v<static_span_non_compliant_type >);
REQUIRE(!mpi::is_compliant_contiguous_sequential_container_v<static_span_non_compliant_type_2d >);
REQUIRE(!mpi::is_compliant_contiguous_sequential_container_v<static_span_non_compliant_type_2_2d >);
REQUIRE( mpi::is_compliant_contiguous_sequential_container_v<dynamic_span_compliant_type >);
REQUIRE(!mpi::is_compliant_contiguous_sequential_container_v<dynamic_span_non_compliant_type_2d >);
REQUIRE( mpi::is_compliant_contiguous_sequential_container_v<valarray_compliant_type >);
REQUIRE( mpi::is_compliant_contiguous_sequential_container_v<valarray_compliant_type_2 >);
REQUIRE(!mpi::is_compliant_contiguous_sequential_container_v<valarray_non_compliant_type >);
#ifdef MPI_USE_RELAXED_TRAITS // It is not possible to detect if the inner types are compliant with relaxed traits.
REQUIRE( mpi::is_compliant_contiguous_sequential_container_v<valarray_non_compliant_type_2 >);
#else
REQUIRE(!mpi::is_compliant_contiguous_sequential_container_v<valarray_non_compliant_type_2 >);
#endif
REQUIRE(!mpi::is_compliant_contiguous_sequential_container_v<valarray_compliant_type_2d >);
REQUIRE(!mpi::is_compliant_contiguous_sequential_container_v<valarray_non_compliant_type_2d >);
REQUIRE( mpi::is_compliant_contiguous_sequential_container_v<vector_compliant_type >);
REQUIRE( mpi::is_compliant_contiguous_sequential_container_v<vector_compliant_type_2 >);
REQUIRE(!mpi::is_compliant_contiguous_sequential_container_v<vector_non_compliant_type >);
#ifdef MPI_USE_RELAXED_TRAITS // It is not possible to detect if the inner types are compliant with relaxed traits.
REQUIRE( mpi::is_compliant_contiguous_sequential_container_v<vector_non_compliant_type_2 >);
#else
REQUIRE(!mpi::is_compliant_contiguous_sequential_container_v<vector_non_compliant_type_2 >);
#endif
REQUIRE(!mpi::is_compliant_contiguous_sequential_container_v<vector_compliant_type_2d >);
REQUIRE(!mpi::is_compliant_contiguous_sequential_container_v<vector_non_compliant_type_2d >);
}