Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
20.meta.unary.comp.cpp
Go to the documentation of this file.
1// -*- C++ -*-
2
30#include <rw_driver.h>
31#include <rw/_defs.h>
32
33// compile out all test code if extensions disabled
34#ifndef _RWSTD_NO_EXT_CXX_0X
35
36#include <type_traits>
37
38
40class class_t {
41 long l_; float f_;
42};
43
44struct struct_t {
45 long l_; float f_;
46};
47
48union union_t {
49 long l_; float f_;
50};
51
52enum enum_t {
54};
55
56
58void test_trait (int line, bool value, bool expect,
59 const char* trait, const char* type)
60{
61 rw_assert (value == expect, 0, line,
62 "%s<%s> is %b, expected %b",
63 trait, type, value, expect);
64}
65
66#define _TEST(Trait,Type,Expect) \
67 test_trait (__LINE__, Trait<Type>::value, Expect, #Trait, #Type)
68
69#define TEST(Trait,Type,Expect) \
70 _TEST(Trait, Type, Expect); \
71 _TEST(Trait, std::add_const<Type>::type, Expect); \
72 _TEST(Trait, std::add_volatile<Type>::type, Expect); \
73 _TEST(Trait, std::add_cv<Type>::type, Expect)
74
75
78{
79 // void
80 TEST (std::is_arithmetic, void, false);
81
82 // integral
83 TEST (std::is_arithmetic, bool, true);
84
85 TEST (std::is_arithmetic, char, true);
86 TEST (std::is_arithmetic, signed char, true);
87 TEST (std::is_arithmetic, unsigned char, true);
88
89#ifndef _RWSTD_NO_WCHAR_T
90 TEST (std::is_arithmetic, wchar_t, true);
91#endif // _RWSTD_NO_WCHAR_T
92
93 TEST (std::is_arithmetic, short, true);
94 TEST (std::is_arithmetic, signed short, true);
95 TEST (std::is_arithmetic, unsigned short, true);
96
97 TEST (std::is_arithmetic, int, true);
98 TEST (std::is_arithmetic, signed int, true);
99 TEST (std::is_arithmetic, unsigned int, true);
100
101 TEST (std::is_arithmetic, long, true);
102 TEST (std::is_arithmetic, signed long, true);
103 TEST (std::is_arithmetic, unsigned long, true);
104
105#ifndef _RWSTD_NO_LONG_LONG
106 TEST (std::is_arithmetic, long long, true);
107 TEST (std::is_arithmetic, signed long long, true);
108 TEST (std::is_arithmetic, unsigned long long, true);
109#endif // _RWSTD_NO_LONG_LONG
110
111 // floating point
112 TEST (std::is_arithmetic, float, true);
113 TEST (std::is_arithmetic, double, true);
114 TEST (std::is_arithmetic, long double, true);
115
116 // array
117 TEST (std::is_arithmetic, long [4], false);
118 TEST (std::is_arithmetic, float [3][3], false);
119 TEST (std::is_arithmetic, char* [4], false);
120 TEST (std::is_arithmetic, class_t [], false);
121 TEST (std::is_arithmetic, struct_t [][2], false);
122
123 // pointer
124 TEST (std::is_arithmetic, long*, false);
125 TEST (std::is_arithmetic, char**, false);
126
127 // reference
128 TEST (std::is_arithmetic, int&, false);
129 TEST (std::is_arithmetic, union_t&, false);
130 TEST (std::is_arithmetic, class_t&, false);
131 TEST (std::is_arithmetic, union_t&, false);
132 TEST (std::is_arithmetic, class_t&, false);
133 TEST (std::is_arithmetic, double&, false);
134
135 // pointer to member
136 TEST (std::is_arithmetic, long (class_t::*), false);
137 TEST (std::is_arithmetic, int (struct_t::*), false);
138
139 // pointer to member function
140 TEST (std::is_arithmetic, double (class_t::*)(), false);
141 TEST (std::is_arithmetic, long (class_t::*)(float), false);
142 TEST (std::is_arithmetic, double (struct_t::*)(), false);
143 TEST (std::is_arithmetic, long (struct_t::*)(float), false);
144
145 // enumeration
146 TEST (std::is_arithmetic, enum_t, false);
147
148 // union
149 TEST (std::is_arithmetic, union_t, false);
150
151 // class
152 TEST (std::is_arithmetic, class_t, false);
153 TEST (std::is_arithmetic, struct_t, false);
154
155 // function
156 TEST (std::is_arithmetic, long (), false);
157 TEST (std::is_arithmetic, float (char), false);
158
159 // function pointer
160 TEST (std::is_arithmetic, long (*)(), false);
161 TEST (std::is_arithmetic, double (*)(int), false);
162
163 // function reference
164 TEST (std::is_arithmetic, long (&)(), false);
165
166 // member function reference
167 //TEST (std::is_arithmetic, long (class_t::&), false);
168}
169
171{
172 // void
173 TEST (std::is_fundamental, void, true);
174
175 // integral
176 TEST (std::is_fundamental, bool, true);
177
178 TEST (std::is_fundamental, char, true);
179 TEST (std::is_fundamental, signed char, true);
180 TEST (std::is_fundamental, unsigned char, true);
181
182#ifndef _RWSTD_NO_WCHAR_T
183 TEST (std::is_fundamental, wchar_t, true);
184#endif // _RWSTD_NO_WCHAR_T
185
186 TEST (std::is_fundamental, short, true);
187 TEST (std::is_fundamental, signed short, true);
188 TEST (std::is_fundamental, unsigned short, true);
189
190 TEST (std::is_fundamental, int, true);
191 TEST (std::is_fundamental, signed int, true);
192 TEST (std::is_fundamental, unsigned int, true);
193
194 TEST (std::is_fundamental, long, true);
195 TEST (std::is_fundamental, signed long, true);
196 TEST (std::is_fundamental, unsigned long, true);
197
198#ifndef _RWSTD_NO_LONG_LONG
199 TEST (std::is_fundamental, long long, true);
200 TEST (std::is_fundamental, signed long long, true);
201 TEST (std::is_fundamental, unsigned long long, true);
202#endif // _RWSTD_NO_LONG_LONG
203
204 // floating point
205 TEST (std::is_fundamental, float, true);
206 TEST (std::is_fundamental, double, true);
207 TEST (std::is_fundamental, long double, true);
208
209 // array
210 TEST (std::is_fundamental, long [4], false);
211 TEST (std::is_fundamental, float [3][3], false);
212 TEST (std::is_fundamental, char* [4], false);
213 TEST (std::is_fundamental, class_t [], false);
214 TEST (std::is_fundamental, struct_t [][2], false);
215
216 // pointer
217 TEST (std::is_fundamental, long*, false);
218 TEST (std::is_fundamental, char**, false);
219
220 // reference
221 TEST (std::is_fundamental, int&, false);
222 TEST (std::is_fundamental, union_t&, false);
223 TEST (std::is_fundamental, class_t&, false);
224 TEST (std::is_fundamental, union_t&, false);
225 TEST (std::is_fundamental, class_t&, false);
226 TEST (std::is_fundamental, double&, false);
227
228 // pointer to member
229 TEST (std::is_fundamental, long (class_t::*), false);
230 TEST (std::is_fundamental, int (struct_t::*), false);
231
232 // pointer to member function
233 TEST (std::is_fundamental, double (class_t::*)(), false);
234 TEST (std::is_fundamental, long (class_t::*)(float), false);
235 TEST (std::is_fundamental, double (struct_t::*)(), false);
236 TEST (std::is_fundamental, long (struct_t::*)(float), false);
237
238 // enumeration
239 TEST (std::is_fundamental, enum_t, false);
240
241 // union
242 TEST (std::is_fundamental, union_t, false);
243
244 // class
245 TEST (std::is_fundamental, class_t, false);
246 TEST (std::is_fundamental, struct_t, false);
247
248 // function
249 TEST (std::is_fundamental, long (), false);
250 TEST (std::is_fundamental, float (char), false);
251
252 // function pointer
253 TEST (std::is_fundamental, long (*)(), false);
254 TEST (std::is_fundamental, double (*)(int), false);
255
256 // function reference
257 TEST (std::is_fundamental, long (&)(), false);
258
259 // member function reference
260 //TEST (std::is_fundamental, long (class_t::&), false);
261}
262
264{
265 // an object type is a (possibly cv-qualified) type that is not a
266 // function type, not a reference type, and not a void type.
267
268 // void
269 TEST (std::is_object, void, false);
270
271 // integral
272 TEST (std::is_object, bool, true);
273
274 TEST (std::is_object, char, true);
275 TEST (std::is_object, signed char, true);
276 TEST (std::is_object, unsigned char, true);
277
278#ifndef _RWSTD_NO_WCHAR_T
279 TEST (std::is_object, wchar_t, true);
280#endif // _RWSTD_NO_WCHAR_T
281
282 TEST (std::is_object, short, true);
283 TEST (std::is_object, signed short, true);
284 TEST (std::is_object, unsigned short, true);
285
286 TEST (std::is_object, int, true);
287 TEST (std::is_object, signed int, true);
288 TEST (std::is_object, unsigned int, true);
289
290 TEST (std::is_object, long, true);
291 TEST (std::is_object, signed long, true);
292 TEST (std::is_object, unsigned long, true);
293
294#ifndef _RWSTD_NO_LONG_LONG
295 TEST (std::is_object, long long, true);
296 TEST (std::is_object, signed long long, true);
297 TEST (std::is_object, unsigned long long, true);
298#endif // _RWSTD_NO_LONG_LONG
299
300 // floating point
301 TEST (std::is_object, float, true);
302 TEST (std::is_object, double, true);
303 TEST (std::is_object, long double, true);
304
305 // array
306 TEST (std::is_object, long [4], true);
307 TEST (std::is_object, float [3][3], true);
308 TEST (std::is_object, char* [4], true);
309 TEST (std::is_object, class_t [], true);
310 TEST (std::is_object, struct_t [][2], true);
311
312 // pointer
313 TEST (std::is_object, long*, true);
314 TEST (std::is_object, char**, true);
315
316 // reference
317 TEST (std::is_object, int&, false);
318 TEST (std::is_object, union_t&, false);
319 TEST (std::is_object, class_t&, false);
320 TEST (std::is_object, union_t&, false);
321 TEST (std::is_object, class_t&, false);
322 TEST (std::is_object, double&, false);
323
324 // pointer to member
325 TEST (std::is_object, long (class_t::*), true);
326 TEST (std::is_object, int (struct_t::*), true);
327
328 // pointer to member function
329 TEST (std::is_object, double (class_t::*)(), true);
330 TEST (std::is_object, long (class_t::*)(float), true);
331 TEST (std::is_object, double (struct_t::*)(), true);
332 TEST (std::is_object, long (struct_t::*)(float), true);
333
334 // enumeration
335 TEST (std::is_object, enum_t, true);
336
337 // union
338 TEST (std::is_object, union_t, true);
339
340 // class
341 TEST (std::is_object, class_t, true);
342 TEST (std::is_object, struct_t, true);
343
344 // function
345 TEST (std::is_object, long (), false);
346 TEST (std::is_object, float (char), false);
347
348 // function pointer
349 TEST (std::is_object, long (*)(), true);
350 TEST (std::is_object, double (*)(int), true);
351
352 // function reference
353 TEST (std::is_object, long (&)(), false);
354
355 // member function reference
356 //TEST (std::is_object, long (class_t::&), false);
357}
358
360{
361 // arithmetic types, enumeration types, pointer types, pointer to member
362 // types and std::nullptr_t, and cv-qualified versions of these types
363 // are collectively called scalar types.
364
365 // void
366 TEST (std::is_scalar, void, false);
367
368 // integral
369 TEST (std::is_scalar, bool, true);
370
371 TEST (std::is_scalar, char, true);
372 TEST (std::is_scalar, signed char, true);
373 TEST (std::is_scalar, unsigned char, true);
374
375#ifndef _RWSTD_NO_WCHAR_T
376 TEST (std::is_scalar, wchar_t, true);
377#endif // _RWSTD_NO_WCHAR_T
378
379 TEST (std::is_scalar, short, true);
380 TEST (std::is_scalar, signed short, true);
381 TEST (std::is_scalar, unsigned short, true);
382
383 TEST (std::is_scalar, int, true);
384 TEST (std::is_scalar, signed int, true);
385 TEST (std::is_scalar, unsigned int, true);
386
387 TEST (std::is_scalar, long, true);
388 TEST (std::is_scalar, signed long, true);
389 TEST (std::is_scalar, unsigned long, true);
390
391#ifndef _RWSTD_NO_LONG_LONG
392 TEST (std::is_scalar, long long, true);
393 TEST (std::is_scalar, signed long long, true);
394 TEST (std::is_scalar, unsigned long long, true);
395#endif // _RWSTD_NO_LONG_LONG
396
397 // floating point
398 TEST (std::is_scalar, float, true);
399 TEST (std::is_scalar, double, true);
400 TEST (std::is_scalar, long double, true);
401
402 // array
403 TEST (std::is_scalar, long [4], false);
404 TEST (std::is_scalar, float [3][3], false);
405 TEST (std::is_scalar, char* [4], false);
406 TEST (std::is_scalar, class_t [], false);
407 TEST (std::is_scalar, struct_t [][2], false);
408
409 // pointer
410 TEST (std::is_scalar, long*, true);
411 TEST (std::is_scalar, char**, true);
412
413 // reference
414 TEST (std::is_scalar, int&, false);
415 TEST (std::is_scalar, union_t&, false);
416 TEST (std::is_scalar, class_t&, false);
417 TEST (std::is_scalar, union_t&, false);
418 TEST (std::is_scalar, class_t&, false);
419 TEST (std::is_scalar, double&, false);
420
421 // pointer to member
422 TEST (std::is_scalar, long (class_t::*), true);
423 TEST (std::is_scalar, int (struct_t::*), true);
424
425 // pointer to member function
426 TEST (std::is_scalar, double (class_t::*)(), true);
427 TEST (std::is_scalar, long (class_t::*)(float), true);
428 TEST (std::is_scalar, double (struct_t::*)(), true);
429 TEST (std::is_scalar, long (struct_t::*)(float), true);
430
431 // enumeration
432 TEST (std::is_scalar, enum_t, true);
433
434 // union
435 TEST (std::is_scalar, union_t, false);
436
437 // class
438 TEST (std::is_scalar, class_t, false);
439 TEST (std::is_scalar, struct_t, false);
440
441 // function
442 TEST (std::is_scalar, long (), false);
443 TEST (std::is_scalar, float (char), false);
444
445 // function pointer
446 TEST (std::is_scalar, long (*)(), true);
447 TEST (std::is_scalar, double (*)(int), true);
448
449 // function reference
450 TEST (std::is_scalar, long (&)(), false);
451
452 // member function reference
453 //TEST (std::is_scalar, long (class_t::&), false);
454}
455
457{
458 // arrays, functions, pointers, function pointers,
459 // references, function references, classes, unions,
460 // enumerations, pointer to non-static class members
461
462 // void
463 TEST (std::is_compound, void, false);
464
465 // integral
466 TEST (std::is_compound, bool, false);
467
468 TEST (std::is_compound, char, false);
469 TEST (std::is_compound, signed char, false);
470 TEST (std::is_compound, unsigned char, false);
471
472#ifndef _RWSTD_NO_WCHAR_T
473 TEST (std::is_compound, wchar_t, false);
474#endif // _RWSTD_NO_WCHAR_T
475
476 TEST (std::is_compound, short, false);
477 TEST (std::is_compound, signed short, false);
478 TEST (std::is_compound, unsigned short, false);
479
480 TEST (std::is_compound, int, false);
481 TEST (std::is_compound, signed int, false);
482 TEST (std::is_compound, unsigned int, false);
483
484 TEST (std::is_compound, long, false);
485 TEST (std::is_compound, signed long, false);
486 TEST (std::is_compound, unsigned long, false);
487
488#ifndef _RWSTD_NO_LONG_LONG
489 TEST (std::is_compound, long long, false);
490 TEST (std::is_compound, signed long long, false);
491 TEST (std::is_compound, unsigned long long, false);
492#endif // _RWSTD_NO_LONG_LONG
493
494 // floating point
495 TEST (std::is_compound, float, false);
496 TEST (std::is_compound, double, false);
497 TEST (std::is_compound, long double, false);
498
499 // array
500 TEST (std::is_compound, long [4], true);
501 TEST (std::is_compound, float [3][3], true);
502 TEST (std::is_compound, char* [4], true);
503 TEST (std::is_compound, class_t [], true);
504 TEST (std::is_compound, struct_t [][2], true);
505
506 // pointer
507 TEST (std::is_compound, void*, true);
508 TEST (std::is_compound, long*, true);
509 TEST (std::is_compound, char**, true);
510
511 // reference
512 TEST (std::is_compound, int&, true);
513 TEST (std::is_compound, union_t&, true);
514 TEST (std::is_compound, class_t&, true);
515 TEST (std::is_compound, union_t&, true);
516 TEST (std::is_compound, class_t&, true);
517 TEST (std::is_compound, double&, true);
518
519#ifndef _RWSTD_NO_RVALUE_REFERENCES
520 TEST (std::is_compound, union_t&&, true);
521 TEST (std::is_compound, double&&, true);
522#endif
523
524 // pointer to member
525 TEST (std::is_compound, long (class_t::*), true);
526 TEST (std::is_compound, int (struct_t::*), true);
527
528 // pointer to member function
529 TEST (std::is_compound, double (class_t::*)(), true);
530 TEST (std::is_compound, long (class_t::*)(float), true);
531 TEST (std::is_compound, double (struct_t::*)(), true);
532 TEST (std::is_compound, long (struct_t::*)(float), true);
533
534 // enumeration
535 TEST (std::is_compound, enum_t, true);
536
537 // union
538 TEST (std::is_compound, union_t, true);
539
540 // class
541 TEST (std::is_compound, class_t, true);
542 TEST (std::is_compound, struct_t, true);
543
544 // function
545 TEST (std::is_compound, long (), true);
546 TEST (std::is_compound, float (char), true);
547
548 // function pointer
549 TEST (std::is_compound, long (*)(), true);
550 TEST (std::is_compound, double (*)(int), true);
551
552 // function reference
553 TEST (std::is_compound, long (&)(), true);
554
555 // member function reference
556 typedef long (class_t::*memfun_t_ptr)();
557 typedef std::remove_pointer<memfun_t_ptr>::type memfun_t;
558 typedef std::add_lvalue_reference<memfun_t>::type memfun_t_ref;
559 TEST (std::is_compound, memfun_t_ref, true);
560}
561
563{
564 // void
565 TEST (std::is_member_pointer, void, false);
566
567 // integral
568 TEST (std::is_member_pointer, bool, false);
569
570 TEST (std::is_member_pointer, char, false);
571 TEST (std::is_member_pointer, signed char, false);
572 TEST (std::is_member_pointer, unsigned char, false);
573
574#ifndef _RWSTD_NO_WCHAR_T
575 TEST (std::is_member_pointer, wchar_t, false);
576#endif // _RWSTD_NO_WCHAR_T
577
578 TEST (std::is_member_pointer, short, false);
579 TEST (std::is_member_pointer, signed short, false);
580 TEST (std::is_member_pointer, unsigned short, false);
581
582 TEST (std::is_member_pointer, int, false);
583 TEST (std::is_member_pointer, signed int, false);
584 TEST (std::is_member_pointer, unsigned int, false);
585
586 TEST (std::is_member_pointer, long, false);
587 TEST (std::is_member_pointer, signed long, false);
588 TEST (std::is_member_pointer, unsigned long, false);
589
590#ifndef _RWSTD_NO_LONG_LONG
591 TEST (std::is_member_pointer, long long, false);
592 TEST (std::is_member_pointer, signed long long, false);
593 TEST (std::is_member_pointer, unsigned long long, false);
594#endif // _RWSTD_NO_LONG_LONG
595
596 // floating point
597 TEST (std::is_member_pointer, float, false);
598 TEST (std::is_member_pointer, double, false);
599 TEST (std::is_member_pointer, long double, false);
600
601 // array
602 TEST (std::is_member_pointer, long [4], false);
603 TEST (std::is_member_pointer, float [3][3], false);
604 TEST (std::is_member_pointer, char* [4], false);
605 TEST (std::is_member_pointer, class_t [], false);
606 TEST (std::is_member_pointer, struct_t [][2], false);
607
608 // pointer
609 TEST (std::is_member_pointer, long*, false);
610 TEST (std::is_member_pointer, char**, false);
611
612 // reference
613 TEST (std::is_member_pointer, int&, false);
614 TEST (std::is_member_pointer, union_t&, false);
615 TEST (std::is_member_pointer, class_t&, false);
616 TEST (std::is_member_pointer, union_t&, false);
617 TEST (std::is_member_pointer, class_t&, false);
618 TEST (std::is_member_pointer, double&, false);
619
620 // pointer to member
621 TEST (std::is_member_pointer, long (class_t::*), true);
622 TEST (std::is_member_pointer, int (struct_t::*), true);
623
624 // pointer to member function
625 TEST (std::is_member_pointer, double (class_t::*)(), true);
626 TEST (std::is_member_pointer, long (class_t::*)(float), true);
627 TEST (std::is_member_pointer, double (struct_t::*)(), true);
628 TEST (std::is_member_pointer, long (struct_t::*)(float), true);
629
630 // enumeration
631 TEST (std::is_member_pointer, enum_t, false);
632
633 // union
634 TEST (std::is_member_pointer, union_t, false);
635
636 // class
637 TEST (std::is_member_pointer, class_t, false);
638 TEST (std::is_member_pointer, struct_t, false);
639
640 // function
641 TEST (std::is_member_pointer, long (), false);
642 TEST (std::is_member_pointer, float (char), false);
643
644 // function pointer
645 TEST (std::is_member_pointer, long (*)(), false);
646 TEST (std::is_member_pointer, double (*)(int), false);
647
648 // function reference
649 TEST (std::is_member_pointer, long (&)(), false);
650
651 // member function reference
652 //TEST (std::is_member_pointer, long (class_t::&), false);
653}
654
655
657static int run_test (int, char*[])
658{
665
666 return 0;
667}
668
669
671#else // _RWSTD_NO_EXT_CXX_0X
672
673
675static int run_test (int, char*[])
676{
677 rw_warn (0, 0, __LINE__,
678 "test disabled because _RWSTD_NO_EXT_CXX_0X is defined");
679 return 0;
680}
681
682#endif // !_RWSTD_NO_EXT_CXX_0X
683
684
686int main (int argc, char*argv[])
687{
688 return rw_test (argc, argv, __FILE__,
689 "meta.unary.comp",
690 0 /* no comment*/,
691 run_test,
692 0);
693}
#define line
Definition 17.names.cpp:490
enum_t
void test_is_arithmetic()
void test_is_fundamental()
void test_is_object()
void test_is_member_pointer()
void test_is_compound()
void test_trait(int line, bool value, bool expect, const char *trait, const char *type)
void test_is_scalar()
#define TEST(Trait, Type, Expect)
void run_test(const ForwardIterator &dummy, T *, Predicate *pred)
T value(const T &val)
#define main
_TEST_EXPORT int rw_test(int argc, char *argv[], const char *filename, const char *clause, const char *comment, int(*testfun)(int, char **), const char *optspec,...)
_TEST_EXPORT int rw_assert(int, const char *, int, const char *,...)
Definition driver.cpp:1630
_TEST_EXPORT int rw_warn(int, const char *, int, const char *,...)
Definition driver.cpp:1647