]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/util/testsuite_common_types.h
cstdatomic: Update to N2798.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / util / testsuite_common_types.h
1 // -*- C++ -*-
2 // typelist for the C++ library testsuite.
3 //
4 // Copyright (C) 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
5 //
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 2, or (at your option)
10 // any later version.
11 //
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING. If not, write to the Free
19 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
20 // USA.
21 //
22 // As a special exception, you may use this file as part of a free software
23 // library without restriction. Specifically, if other files instantiate
24 // templates or use macros or inline functions from this file, or you compile
25 // this file and link it with other files to produce an executable, this
26 // file does not by itself cause the resulting executable to be covered by
27 // the GNU General Public License. This exception does not however
28 // invalidate any other reasons why the executable file might be covered by
29 // the GNU General Public License.
30
31 #ifndef _TESTSUITE_COMMON_TYPES_H
32 #define _TESTSUITE_COMMON_TYPES_H 1
33
34 #include <ext/typelist.h>
35
36 #include <ext/new_allocator.h>
37 #include <ext/malloc_allocator.h>
38 #include <ext/mt_allocator.h>
39 #include <ext/bitmap_allocator.h>
40 #include <ext/pool_allocator.h>
41
42 #include <algorithm>
43
44 #include <vector>
45 #include <list>
46 #include <deque>
47 #include <string>
48
49 #include <map>
50 #include <set>
51 #include <tr1/functional>
52 #include <tr1/unordered_map>
53 #include <tr1/unordered_set>
54
55 #ifdef __GXX_EXPERIMENTAL_CXX0X__
56 #include <cstdatomic>
57 #include <type_traits>
58 #endif
59
60 namespace __gnu_test
61 {
62 using __gnu_cxx::typelist::node;
63 using __gnu_cxx::typelist::transform;
64 using __gnu_cxx::typelist::append;
65
66 // All the allocators to test.
67 template<typename Tp, bool Thread>
68 struct allocator_policies
69 {
70 typedef Tp value_type;
71 typedef __gnu_cxx::new_allocator<Tp> a1;
72 typedef __gnu_cxx::malloc_allocator<Tp> a2;
73 typedef __gnu_cxx::__common_pool_policy<__gnu_cxx::__pool, Thread> pool_policy;
74 typedef __gnu_cxx::__mt_alloc<Tp, pool_policy> a3;
75 typedef __gnu_cxx::bitmap_allocator<Tp> a4;
76 typedef __gnu_cxx::__pool_alloc<Tp> a5;
77 typedef node<_GLIBCXX_TYPELIST_CHAIN5(a1, a2, a3, a4, a5)> type;
78 };
79
80 // Typelists for vector, string, list, deque.
81 // XXX should just use template templates
82 template<typename Tp, bool Thread>
83 struct vectors
84 {
85 typedef Tp value_type;
86
87 template<typename Tl>
88 struct vector_shell
89 {
90 typedef Tl allocator_type;
91 typedef std::vector<value_type, allocator_type> type;
92 };
93
94 typedef allocator_policies<value_type, Thread> allocator_types;
95 typedef typename allocator_types::type allocator_typelist;
96 typedef typename transform<allocator_typelist, vector_shell>::type type;
97 };
98
99 template<typename Tp, bool Thread>
100 struct lists
101 {
102 typedef Tp value_type;
103
104 template<typename Tl>
105 struct list_shell
106 {
107 typedef Tl allocator_type;
108 typedef std::list<value_type, allocator_type> type;
109 };
110
111 typedef allocator_policies<value_type, Thread> allocator_types;
112 typedef typename allocator_types::type allocator_typelist;
113 typedef typename transform<allocator_typelist, list_shell>::type type;
114 };
115
116 template<typename Tp, bool Thread>
117 struct deques
118 {
119 typedef Tp value_type;
120
121 template<typename Tl>
122 struct deque_shell
123 {
124 typedef Tl allocator_type;
125 typedef std::deque<value_type, allocator_type> type;
126 };
127
128 typedef allocator_policies<value_type, Thread> allocator_types;
129 typedef typename allocator_types::type allocator_typelist;
130 typedef typename transform<allocator_typelist, deque_shell>::type type;
131 };
132
133 template<typename Tp, bool Thread>
134 struct strings
135 {
136 typedef Tp value_type;
137
138 template<typename Tl>
139 struct string_shell
140 {
141 typedef Tl allocator_type;
142 typedef std::char_traits<value_type> traits_type;
143 typedef std::basic_string<value_type, traits_type, allocator_type> type;
144 };
145
146 typedef allocator_policies<value_type, Thread> allocator_types;
147 typedef typename allocator_types::type allocator_typelist;
148 typedef typename transform<allocator_typelist, string_shell>::type type;
149 };
150
151 // A typelist of vector, list, deque, and string all instantiated
152 // with each of the allocator policies.
153 template<typename Tp, bool Thread>
154 struct sequence_containers
155 {
156 typedef Tp value_type;
157
158 typedef typename vectors<value_type, Thread>::type vector_typelist;
159 typedef typename lists<value_type, Thread>::type list_typelist;
160 typedef typename deques<value_type, Thread>::type deque_typelist;
161 typedef typename strings<value_type, Thread>::type string_typelist;
162
163 typedef typename append<vector_typelist, list_typelist>::type a1;
164 typedef typename append<deque_typelist, string_typelist>::type a2;
165 typedef typename append<a1, a2>::type type;
166 };
167
168 // Typelists for map, set, unordered_set, unordered_map.
169 template<typename Tp, bool Thread>
170 struct maps
171 {
172 typedef Tp value_type;
173 typedef Tp key_type;
174 typedef std::pair<const key_type, value_type> pair_type;
175 typedef std::less<key_type> compare_function;
176
177 template<typename Tl>
178 struct container
179 {
180 typedef Tl allocator_type;
181 typedef std::map<key_type, value_type, compare_function, allocator_type> type;
182 };
183
184 typedef allocator_policies<pair_type, Thread> allocator_types;
185 typedef typename allocator_types::type allocator_typelist;
186 typedef typename transform<allocator_typelist, container>::type type;
187 };
188
189 template<typename Tp, bool Thread>
190 struct unordered_maps
191 {
192 typedef Tp value_type;
193 typedef Tp key_type;
194 typedef std::pair<const key_type, value_type> pair_type;
195 typedef std::tr1::hash<key_type> hash_function;
196 typedef std::equal_to<key_type> equality_function;
197
198 template<typename Tl>
199 struct container
200 {
201 typedef Tl allocator_type;
202 typedef std::tr1::unordered_map<key_type, value_type, hash_function, equality_function, allocator_type> type;
203 };
204
205 typedef allocator_policies<pair_type, Thread> allocator_types;
206 typedef typename allocator_types::type allocator_typelist;
207 typedef typename transform<allocator_typelist, container>::type type;
208 };
209
210 template<typename Tp, bool Thread>
211 struct sets
212 {
213 typedef Tp value_type;
214 typedef Tp key_type;
215 typedef std::less<key_type> compare_function;
216
217 template<typename Tl>
218 struct container
219 {
220 typedef Tl allocator_type;
221 typedef std::set<key_type, compare_function, allocator_type> type;
222 };
223
224 typedef allocator_policies<key_type, Thread> allocator_types;
225 typedef typename allocator_types::type allocator_typelist;
226 typedef typename transform<allocator_typelist, container>::type type;
227 };
228
229 template<typename Tp, bool Thread>
230 struct unordered_sets
231 {
232 typedef Tp value_type;
233 typedef Tp key_type;
234 typedef std::tr1::hash<key_type> hash_function;
235 typedef std::equal_to<key_type> equality_function;
236
237 template<typename Tl>
238 struct container
239 {
240 typedef Tl allocator_type;
241 typedef std::tr1::unordered_set<key_type, hash_function, equality_function, allocator_type> type;
242 };
243
244 typedef allocator_policies<key_type, Thread> allocator_types;
245 typedef typename allocator_types::type allocator_typelist;
246 typedef typename transform<allocator_typelist, container>::type type;
247 };
248
249
250 // A typelist of all associated container types, with each of the
251 // allocator policies.
252 template<typename Tp, bool Thread>
253 struct associative_containers
254 {
255 typedef Tp value_type;
256
257 typedef typename maps<value_type, Thread>::type map_typelist;
258 typedef typename sets<value_type, Thread>::type set_typelist;
259 typedef typename unordered_maps<value_type, Thread>::type unordered_map_typelist;
260 typedef typename unordered_sets<value_type, Thread>::type unordered_set_typelist;
261
262 typedef typename append<map_typelist, unordered_map_typelist>::type a1;
263 typedef typename append<set_typelist, unordered_set_typelist>::type a2;
264 typedef typename append<a1, a2>::type type;
265 };
266
267 // A typelist of all integral types.
268 struct integral_types
269 {
270 typedef bool a1;
271 typedef char a2;
272 typedef signed char a3;
273 typedef unsigned char a4;
274 typedef short a5;
275 typedef unsigned short a6;
276 typedef int a7;
277 typedef unsigned int a8;
278 typedef long a9;
279 typedef unsigned long a10;
280 typedef long long a11;
281 typedef unsigned long long a12;
282 typedef wchar_t a13;
283 #ifdef __GXX_EXPERIMENTAL_CXX0X__
284 typedef char16_t a14;
285 typedef char32_t a15;
286
287 typedef node<_GLIBCXX_TYPELIST_CHAIN15(a1, a2, a3, a4, a5, a6, a7, a8, a9,
288 a10, a11, a12, a13, a14, a15)> type;
289 #else
290 typedef node<_GLIBCXX_TYPELIST_CHAIN13(a1, a2, a3, a4, a5, a6, a7, a8, a9,
291 a10, a11, a12, a13)> type;
292 #endif
293 };
294
295 #ifdef __GXX_EXPERIMENTAL_CXX0X__
296 struct atomic_integrals_no_bool
297 {
298 typedef std::atomic_char a2;
299 typedef std::atomic_schar a3;
300 typedef std::atomic_uchar a4;
301 typedef std::atomic_short a5;
302 typedef std::atomic_ushort a6;
303 typedef std::atomic_int a7;
304 typedef std::atomic_uint a8;
305 typedef std::atomic_long a9;
306 typedef std::atomic_ulong a10;
307 typedef std::atomic_llong a11;
308 typedef std::atomic_ullong a12;
309 typedef std::atomic_wchar_t a13;
310 typedef std::atomic_char16_t a14;
311 typedef std::atomic_char32_t a15;
312
313 typedef node<_GLIBCXX_TYPELIST_CHAIN14(a2, a3, a4, a5, a6, a7, a8, a9,
314 a10, a11, a12, a13, a14, a15)> type;
315 };
316
317 struct atomic_integrals
318 {
319 typedef std::atomic_bool a1;
320 typedef std::atomic_char a2;
321 typedef std::atomic_schar a3;
322 typedef std::atomic_uchar a4;
323 typedef std::atomic_short a5;
324 typedef std::atomic_ushort a6;
325 typedef std::atomic_int a7;
326 typedef std::atomic_uint a8;
327 typedef std::atomic_long a9;
328 typedef std::atomic_ulong a10;
329 typedef std::atomic_llong a11;
330 typedef std::atomic_ullong a12;
331 typedef std::atomic_wchar_t a13;
332 typedef std::atomic_char16_t a14;
333 typedef std::atomic_char32_t a15;
334
335 typedef node<_GLIBCXX_TYPELIST_CHAIN15(a1, a2, a3, a4, a5, a6, a7, a8, a9,
336 a10, a11, a12, a13, a14, a15)> type;
337 };
338
339
340 template<typename Tp>
341 struct atomics
342 {
343 typedef Tp value_type;
344 typedef std::atomic<value_type> type;
345 };
346
347 typedef transform<integral_types::type, atomics>::type atomics_tl;
348 #endif
349
350
351 struct has_increment_operators
352 {
353 template<typename _Tp>
354 void
355 operator()()
356 {
357 struct _Concept
358 {
359 void __constraint()
360 {
361 _Tp a;
362 ++a; // prefix
363 a++; // postfix
364 a += a;
365 }
366 };
367
368 void (_Concept::*__x)() __attribute__((unused))
369 = &_Concept::__constraint;
370 }
371 };
372
373 struct has_decrement_operators
374 {
375 template<typename _Tp>
376 void
377 operator()()
378 {
379 struct _Concept
380 {
381 void __constraint()
382 {
383 _Tp a;
384 --a; // prefix
385 a--; // postfix
386 a -= a;
387 }
388 };
389
390 void (_Concept::*__x)() __attribute__((unused))
391 = &_Concept::__constraint;
392 }
393 };
394
395 template<typename _Tp>
396 void
397 bitwise_operators()
398 {
399 _Tp a;
400 _Tp b;
401 a | b;
402 a & b;
403 a ^ b;
404 ~b;
405 }
406
407 template<typename _Tp>
408 void
409 bitwise_assignment_operators()
410 {
411 _Tp a;
412 _Tp b;
413 a |= b; // set
414 a &= ~b; // clear
415 a ^= b;
416 }
417
418 // 17.3.2.1.2 - Bitmask types [lib.bitmask.types]
419 // bitmask_operators
420 template<typename _BitmTp>
421 void
422 bitmask_operators()
423 {
424 bitwise_operators<_BitmTp>();
425 bitwise_assignment_operators<_BitmTp>();
426 }
427
428 struct has_bitwise_operators
429 {
430 template<typename _Tp>
431 void
432 operator()()
433 {
434 struct _Concept
435 {
436 void __constraint()
437 {
438 bitwise_assignment_operators<_Tp>();
439 }
440 };
441
442 void (_Concept::*__x)() __attribute__((unused))
443 = &_Concept::__constraint;
444 }
445 };
446
447 // Generator to test standard layout
448 #ifdef __GXX_EXPERIMENTAL_CXX0X__
449 struct standard_layout
450 {
451 template<typename _Tp>
452 void
453 operator()()
454 {
455 struct _Concept
456 {
457 void __constraint()
458 {
459 // libstdc++/37907
460 // typedef std::is_standard_layout<_Tp> standard_layout_p;
461 // static_assert(standard_layout_p::value, "not standard_layout");
462
463 typedef std::has_trivial_default_constructor<_Tp> ctor_p;
464 static_assert(ctor_p::value, "default ctor not trivial");
465
466 typedef std::has_trivial_destructor<_Tp> dtor_p;
467 static_assert(dtor_p::value, "dtor not trivial");
468 }
469 };
470
471 void (_Concept::*__x)() __attribute__((unused))
472 = &_Concept::__constraint;
473 }
474 };
475 #endif
476
477 // Generator to test base class
478 struct has_required_base_class
479 {
480 template<typename _TBase, typename _TDerived>
481 void
482 operator()()
483 {
484 struct _Concept
485 {
486 void __constraint()
487 {
488 const _TDerived& obj = __a;
489 const _TBase* base __attribute__((unused)) = &obj;
490 }
491
492 _TDerived __a;
493 };
494
495 void (_Concept::*__x)() __attribute__((unused))
496 = &_Concept::__constraint;
497 }
498 };
499
500 // Generator to test assignment operator.
501 struct assignable
502 {
503 template<typename _Tp>
504 void
505 operator()()
506 {
507 struct _Concept
508 {
509 void __constraint()
510 { __v1 = __v2; }
511
512 _Tp __v1;
513 _Tp __v2;
514 };
515
516 void (_Concept::*__x)() __attribute__((unused))
517 = &_Concept::__constraint;
518 }
519 };
520
521 // Generator to test default constructor.
522 struct default_constructible
523 {
524 template<typename _Tp>
525 void
526 operator()()
527 {
528 struct _Concept
529 {
530 void __constraint()
531 { _Tp __v; }
532 };
533
534 void (_Concept::*__x)() __attribute__((unused))
535 = &_Concept::__constraint;
536 }
537 };
538
539 // Generator to test copy constructor.
540 struct copy_constructible
541 {
542 template<typename _Tp>
543 void
544 operator()()
545 {
546 struct _Concept
547 {
548 void __constraint()
549 { _Tp __v2(__v1); }
550
551 _Tp __v1;
552 };
553
554 void (_Concept::*__x)() __attribute__((unused))
555 = &_Concept::__constraint;
556 }
557 };
558
559 // Generator to test direct initialization, single value constructor.
560 struct single_value_constructible
561 {
562 template<typename _Ttype, typename _Tvalue>
563 void
564 operator()()
565 {
566 struct _Concept
567 {
568 void __constraint()
569 { _Ttype __v(__a); }
570
571 _Tvalue __a;
572 };
573
574 void (_Concept::*__x)() __attribute__((unused))
575 = &_Concept::__constraint;
576 }
577 };
578
579 // Generator to test direct list initialization
580 #ifdef __GXX_EXPERIMENTAL_CXX0X__
581 struct direct_list_initializable
582 {
583 template<typename _Ttype, typename _Tvalue>
584 void
585 operator()()
586 {
587 struct _Concept
588 {
589 void __constraint()
590 {
591 _Ttype __v1 { }; // default ctor
592 _Ttype __v2 { __a }; // single-argument ctor
593 }
594
595 _Tvalue __a;
596 };
597
598 void (_Concept::*__x)() __attribute__((unused))
599 = &_Concept::__constraint;
600 }
601 };
602 #endif
603
604 // Generator to test copy list initialization, aggregate initialization
605 struct copy_list_initializable
606 {
607 template<typename _Ttype, typename _Tvalue>
608 void
609 operator()()
610 {
611 struct _Concept
612 {
613 void __constraint()
614 { _Ttype __v = {__a}; }
615
616 _Tvalue __a;
617 };
618
619 void (_Concept::*__x)() __attribute__((unused))
620 = &_Concept::__constraint;
621 }
622 };
623
624 // Generator to test integral conversion operator
625 struct integral_convertable
626 {
627 template<typename _Ttype, typename _Tvalue>
628 void
629 operator()()
630 {
631 struct _Concept
632 {
633 void __constraint()
634 {
635 _Tvalue __v0(0);
636 _Tvalue __v1(1);
637 _Ttype __a(__v1);
638 __v0 = __a;
639
640 bool test __attribute__((unused)) = true;
641 VERIFY( __v1 == __v0 );
642 }
643 };
644
645 void (_Concept::*__x)() __attribute__((unused))
646 = &_Concept::__constraint;
647 }
648 };
649
650 // Generator to test integral assignment operator
651 struct integral_assignable
652 {
653 template<typename _Ttype, typename _Tvalue>
654 void
655 operator()()
656 {
657 struct _Concept
658 {
659 void __constraint()
660 {
661 _Tvalue __v0(0);
662 _Tvalue __v1(1);
663 _Ttype __a(__v0);
664 __a = __v1;
665 _Tvalue __vr = __a;
666
667 bool test __attribute__((unused)) = true;
668 VERIFY( __v1 == __vr );
669 }
670 };
671
672 void (_Concept::*__x)() __attribute__((unused))
673 = &_Concept::__constraint;
674 }
675 };
676 } // namespace __gnu_test
677 #endif