-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_common_type.cpp
410 lines (339 loc) · 12.5 KB
/
test_common_type.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
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
//
// Copyright 2015 Peter Dimov
//
// Distributed under the Boost Software License, Version 1.0.
// See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
//
#include "common_type.hpp"
#include <boost/type_traits/is_same.hpp>
#include <boost/type_traits/is_convertible.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/core/lightweight_test_trait.hpp>
//
template<class T, class U, class E> void test()
{
typedef typename boost::common_type<T, U>::type C;
BOOST_TEST_TRAIT_TRUE((boost::is_same<C, E>));
BOOST_TEST_TRAIT_TRUE((boost::is_convertible<T, C>));
BOOST_TEST_TRAIT_TRUE((boost::is_convertible<U, C>));
}
//
struct C1 {};
struct C2 {};
struct C3: C2 {};
struct C1C2
{
C1C2(C1 const&) {}
C1C2(C2 const&) {}
};
enum E1
{
e1
};
enum E2
{
e2
};
struct C4
{
C4( int ) {}
};
struct C5
{
C5( E1 ) {}
};
struct C6
{
operator E2() const { return e2; }
};
template<class T> struct C7
{
operator T() const { return 0; }
};
template<class T> struct C8
{
operator T() const { return 0; }
};
static void test_class_types()
{
test<C1C2&, C1&, C1C2>();
test<C1C2&, C2&, C1C2>();
test<C1, C1C2, C1C2>();
test<C2, C1C2, C1C2>();
test<C1C2, C1, C1C2>();
test<C1C2, C2, C1C2>();
test<C2&, C3&, C2>();
test<C3&, C2&, C2>();
test<int, C4, C4>();
test<C4, int, C4>();
test<int&, C4&, C4>();
test<C4&, int&, C4>();
test<E1, C4, C4>();
test<C4, E1, C4>();
test<E1&, C4&, C4>();
test<C4&, E1&, C4>();
test<E1, C5, C5>();
test<C5, E1, C5>();
test<E1&, C5&, C5>();
test<C5&, E1&, C5>();
test<E2, C6, E2>();
test<C6, E2, E2>();
test<E2&, C6&, E2>();
test<C6&, E2&, E2>();
test<int, C6, int>();
test<C6, int, int>();
test<int&, C6&, int>();
test<C6&, int&, int>();
}
static void test_arithmetic_types()
{
test<char, char, char>();
test<char, unsigned char, int>();
test<char, short, int>();
test<char, unsigned short, int>();
test<char, int, int>();
test<char, unsigned int, unsigned int>();
test<char, long long, long long>();
test<char, unsigned long long, unsigned long long>();
test<char, float, float>();
test<char, double, double>();
test<char, long double, long double>();
test<char, E1, int>();
test<unsigned char, char, int>();
test<unsigned char, unsigned char, unsigned char>();
test<unsigned char, short, int>();
test<unsigned char, unsigned short, int>();
test<unsigned char, int, int>();
test<unsigned char, unsigned int, unsigned int>();
test<unsigned char, long long, long long>();
test<unsigned char, unsigned long long, unsigned long long>();
test<unsigned char, float, float>();
test<unsigned char, double, double>();
test<unsigned char, long double, long double>();
test<unsigned char, E1, int>();
test<short, char, int>();
test<short, unsigned char, int>();
test<short, short, short>();
test<short, unsigned short, int>();
test<short, int, int>();
test<short, unsigned int, unsigned int>();
test<short, long long, long long>();
test<short, unsigned long long, unsigned long long>();
test<short, float, float>();
test<short, double, double>();
test<short, long double, long double>();
test<short, E1, int>();
test<unsigned short, char, int>();
test<unsigned short, unsigned char, int>();
test<unsigned short, short, int>();
test<unsigned short, unsigned short, unsigned short>();
test<unsigned short, int, int>();
test<unsigned short, unsigned int, unsigned int>();
test<unsigned short, long long, long long>();
test<unsigned short, unsigned long long, unsigned long long>();
test<unsigned short, float, float>();
test<unsigned short, double, double>();
test<unsigned short, long double, long double>();
test<unsigned short, E1, int>();
test<int, char, int>();
test<int, unsigned char, int>();
test<int, short, int>();
test<int, unsigned short, int>();
test<int, int, int>();
test<int, unsigned int, unsigned int>();
test<int, long long, long long>();
test<int, unsigned long long, unsigned long long>();
test<int, float, float>();
test<int, double, double>();
test<int, long double, long double>();
test<int, E1, int>();
test<unsigned int, char, unsigned int>();
test<unsigned int, unsigned char, unsigned int>();
test<unsigned int, short, unsigned int>();
test<unsigned int, unsigned short, unsigned int>();
test<unsigned int, int, unsigned int>();
test<unsigned int, unsigned int, unsigned int>();
test<unsigned int, long long, long long>();
test<unsigned int, unsigned long long, unsigned long long>();
test<unsigned int, float, float>();
test<unsigned int, double, double>();
test<unsigned int, long double, long double>();
test<unsigned int, E1, unsigned int>();
test<long long, char, long long>();
test<long long, unsigned char, long long>();
test<long long, short, long long>();
test<long long, unsigned short, long long>();
test<long long, int, long long>();
test<long long, unsigned int, long long>();
test<long long, long long, long long>();
test<long long, unsigned long long, unsigned long long>();
test<long long, float, float>();
test<long long, double, double>();
test<long long, long double, long double>();
test<long long, E1, long long>();
test<unsigned long long, char, unsigned long long>();
test<unsigned long long, unsigned char, unsigned long long>();
test<unsigned long long, short, unsigned long long>();
test<unsigned long long, unsigned short, unsigned long long>();
test<unsigned long long, int, unsigned long long>();
test<unsigned long long, unsigned int, unsigned long long>();
test<unsigned long long, long long, unsigned long long>();
test<unsigned long long, unsigned long long, unsigned long long>();
test<unsigned long long, float, float>();
test<unsigned long long, double, double>();
test<unsigned long long, long double, long double>();
test<unsigned long long, E1, unsigned long long>();
test<float, char, float>();
test<float, unsigned char, float>();
test<float, short, float>();
test<float, unsigned short, float>();
test<float, int, float>();
test<float, unsigned int, float>();
test<float, long long, float>();
test<float, unsigned long long, float>();
test<float, float, float>();
test<float, double, double>();
test<float, long double, long double>();
test<float, E1, float>();
test<double, char, double>();
test<double, unsigned char, double>();
test<double, short, double>();
test<double, unsigned short, double>();
test<double, int, double>();
test<double, unsigned int, double>();
test<double, long long, double>();
test<double, unsigned long long, double>();
test<double, float, double>();
test<double, double, double>();
test<double, long double, long double>();
test<double, E1, double>();
test<long double, char, long double>();
test<long double, unsigned char, long double>();
test<long double, short, long double>();
test<long double, unsigned short, long double>();
test<long double, int, long double>();
test<long double, unsigned int, long double>();
test<long double, long long, long double>();
test<long double, unsigned long long, long double>();
test<long double, float, long double>();
test<long double, double, long double>();
test<long double, long double, long double>();
test<long double, E1, long double>();
test<E1, char, int>();
test<E1, unsigned char, int>();
test<E1, short, int>();
test<E1, unsigned short, int>();
test<E1, int, int>();
test<E1, unsigned int, unsigned int>();
test<E1, long long, long long>();
test<E1, unsigned long long, unsigned long long>();
test<E1, float, float>();
test<E1, double, double>();
test<E1, long double, long double>();
test<E1, E1, E1>();
test<E1, E2, int>();
//
test<int const, int const, int>();
test<int const, long const, long>();
//
test<C7<char>, char, char>();
test<C7<char>, unsigned char, unsigned char>();
test<C7<char>, short, short>();
test<C7<char>, unsigned short, unsigned short>();
test<C7<char>, int, int>();
test<C7<char>, unsigned int, unsigned int>();
test<C7<char>, long long, long long>();
test<C7<char>, unsigned long long, unsigned long long>();
test<C7<char>, float, float>();
test<C7<char>, double, double>();
test<C7<char>, long double, long double>();
#if !defined( BOOST_MSVC ) || ( BOOST_MSVC > 1800 )
// msvc-8.0, msvc-10.0, msvc-11.0, msvc-12.0 fail to compile x? C7<T>(): C7<U>()
test<C7<char>, C7<char>, C7<char> >();
test<C7<char>, C8<char>, int>();
test<C7<char>, C7<unsigned char>, int>();
test<C7<char>, C7<short>, int>();
test<C7<char>, C7<unsigned short>, int>();
test<C7<char>, C7<int>, int>();
test<C7<char>, C7<unsigned int>, unsigned int>();
test<C7<char>, C7<long long>, long long>();
test<C7<char>, C7<unsigned long long>, unsigned long long>();
test<C7<char>, C7<float>, float>();
test<C7<char>, C7<double>, double>();
test<C7<char>, C7<long double>, long double>();
#endif
#if defined( BOOST_HAS_INT128 )
test<__int128, char, __int128>();
test<__int128, unsigned char, __int128>();
test<__int128, short, __int128>();
test<__int128, unsigned short, __int128>();
test<__int128, int, __int128>();
test<__int128, unsigned int, __int128>();
test<__int128, long long, __int128>();
test<__int128, unsigned long long, __int128>();
test<__int128, float, float>();
test<__int128, double, double>();
test<__int128, long double, long double>();
test<__int128, E1, __int128>();
test<__int128, __int128, __int128>();
test<__int128, unsigned __int128, unsigned __int128>();
test<unsigned __int128, char, unsigned __int128>();
test<unsigned __int128, unsigned char, unsigned __int128>();
test<unsigned __int128, short, unsigned __int128>();
test<unsigned __int128, unsigned short, unsigned __int128>();
test<unsigned __int128, int, unsigned __int128>();
test<unsigned __int128, unsigned int, unsigned __int128>();
test<unsigned __int128, long long, unsigned __int128>();
test<unsigned __int128, unsigned long long, unsigned __int128>();
test<unsigned __int128, float, float>();
test<unsigned __int128, double, double>();
test<unsigned __int128, long double, long double>();
test<unsigned __int128, E1, unsigned __int128>();
test<unsigned __int128, __int128, unsigned __int128>();
test<unsigned __int128, unsigned __int128, unsigned __int128>();
#endif
}
static void test_pointer_types()
{
test<int*, int const*, int const*>();
test<int*, int volatile*, int volatile*>();
test<int const*, int volatile*, int const volatile*>();
test<int*, void const*, void const*>();
test<void*, int const*, void const*>();
test<int*, void volatile*, void volatile*>();
test<void*, int volatile*, void volatile*>();
test<int const*, void volatile*, void const volatile*>();
test<void const*, int volatile*, void const volatile*>();
test<int const* const*, int volatile* const*, int const volatile* const*>();
test<int[], int[], int*>();
test<int[], int const[], int const*>();
test<int volatile[], int const[], int const volatile*>();
test<int volatile* const[], int const* const[], int const volatile* const*>();
test<C3*, C2*, C2*>();
test<C2*, C3*, C2*>();
test<C3 const*, C2 volatile*, C2 const volatile*>();
test<C2 const*, C3 volatile*, C2 const volatile*>();
}
static void test_member_pointer_types()
{
test<int C1::*, int const C1::*, int const C1::*>();
test<int C1::*, int volatile C1::*, int volatile C1::*>();
test<int C2::*, int const C3::*, int const C3::*>();
test<int C2::*, int volatile C3::*, int volatile C3::*>();
#if !defined(BOOST_MSVC) || BOOST_MSVC < 1600 || BOOST_MSVC > 1800
test<int const C1::*, int volatile C1::*, int const volatile C1::*>();
test<int const C2::*, int volatile C3::*, int const volatile C3::*>();
test<int C3::*, int const C2::*, int const C3::*>();
test<int C3::*, int volatile C2::*, int volatile C3::*>();
test<int const C3::*, int volatile C2::*, int const volatile C3::*>();
#endif
}
int main()
{
test_class_types();
test_arithmetic_types();
test_pointer_types();
test_member_pointer_types();
return boost::report_errors();
}