2009-07-17 Richard Guenther <rguenther@suse.de>
[official-gcc.git] / libstdc++-v3 / testsuite / util / testsuite_common_types.h
blobc6c00689f3da8a5f0cec837b2d25e8f09cc47c82
1 // -*- C++ -*-
2 // typelist for the C++ library testsuite.
3 //
4 // Copyright (C) 2005, 2006, 2007, 2008, 2009 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 3, or (at your option)
10 // any later version.
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.
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING3. If not see
19 // <http://www.gnu.org/licenses/>.
22 #ifndef _TESTSUITE_COMMON_TYPES_H
23 #define _TESTSUITE_COMMON_TYPES_H 1
25 #include <ext/typelist.h>
27 #include <ext/new_allocator.h>
28 #include <ext/malloc_allocator.h>
29 #include <ext/mt_allocator.h>
30 #include <ext/bitmap_allocator.h>
31 #include <ext/pool_allocator.h>
33 #include <algorithm>
35 #include <vector>
36 #include <list>
37 #include <deque>
38 #include <string>
40 #include <map>
41 #include <set>
42 #include <tr1/functional>
43 #include <tr1/unordered_map>
44 #include <tr1/unordered_set>
46 #ifdef __GXX_EXPERIMENTAL_CXX0X__
47 #include <cstdatomic>
48 #include <type_traits>
49 #endif
51 namespace __gnu_test
53 using __gnu_cxx::typelist::node;
54 using __gnu_cxx::typelist::transform;
55 using __gnu_cxx::typelist::append;
57 // All the allocators to test.
58 template<typename Tp, bool Thread>
59 struct allocator_policies
61 typedef Tp value_type;
62 typedef __gnu_cxx::new_allocator<Tp> a1;
63 typedef __gnu_cxx::malloc_allocator<Tp> a2;
64 typedef __gnu_cxx::__common_pool_policy<__gnu_cxx::__pool, Thread> pool_policy;
65 typedef __gnu_cxx::__mt_alloc<Tp, pool_policy> a3;
66 typedef __gnu_cxx::bitmap_allocator<Tp> a4;
67 typedef __gnu_cxx::__pool_alloc<Tp> a5;
68 typedef node<_GLIBCXX_TYPELIST_CHAIN5(a1, a2, a3, a4, a5)> type;
71 // Typelists for vector, string, list, deque.
72 // XXX should just use template templates
73 template<typename Tp, bool Thread>
74 struct vectors
76 typedef Tp value_type;
78 template<typename Tl>
79 struct vector_shell
81 typedef Tl allocator_type;
82 typedef std::vector<value_type, allocator_type> type;
85 typedef allocator_policies<value_type, Thread> allocator_types;
86 typedef typename allocator_types::type allocator_typelist;
87 typedef typename transform<allocator_typelist, vector_shell>::type type;
90 template<typename Tp, bool Thread>
91 struct lists
93 typedef Tp value_type;
95 template<typename Tl>
96 struct list_shell
98 typedef Tl allocator_type;
99 typedef std::list<value_type, allocator_type> type;
102 typedef allocator_policies<value_type, Thread> allocator_types;
103 typedef typename allocator_types::type allocator_typelist;
104 typedef typename transform<allocator_typelist, list_shell>::type type;
107 template<typename Tp, bool Thread>
108 struct deques
110 typedef Tp value_type;
112 template<typename Tl>
113 struct deque_shell
115 typedef Tl allocator_type;
116 typedef std::deque<value_type, allocator_type> type;
119 typedef allocator_policies<value_type, Thread> allocator_types;
120 typedef typename allocator_types::type allocator_typelist;
121 typedef typename transform<allocator_typelist, deque_shell>::type type;
124 template<typename Tp, bool Thread>
125 struct strings
127 typedef Tp value_type;
129 template<typename Tl>
130 struct string_shell
132 typedef Tl allocator_type;
133 typedef std::char_traits<value_type> traits_type;
134 typedef std::basic_string<value_type, traits_type, allocator_type> type;
137 typedef allocator_policies<value_type, Thread> allocator_types;
138 typedef typename allocator_types::type allocator_typelist;
139 typedef typename transform<allocator_typelist, string_shell>::type type;
142 // A typelist of vector, list, deque, and string all instantiated
143 // with each of the allocator policies.
144 template<typename Tp, bool Thread>
145 struct sequence_containers
147 typedef Tp value_type;
149 typedef typename vectors<value_type, Thread>::type vector_typelist;
150 typedef typename lists<value_type, Thread>::type list_typelist;
151 typedef typename deques<value_type, Thread>::type deque_typelist;
152 typedef typename strings<value_type, Thread>::type string_typelist;
154 typedef typename append<vector_typelist, list_typelist>::type a1;
155 typedef typename append<deque_typelist, string_typelist>::type a2;
156 typedef typename append<a1, a2>::type type;
159 // Typelists for map, set, unordered_set, unordered_map.
160 template<typename Tp, bool Thread>
161 struct maps
163 typedef Tp value_type;
164 typedef Tp key_type;
165 typedef std::pair<const key_type, value_type> pair_type;
166 typedef std::less<key_type> compare_function;
168 template<typename Tl>
169 struct container
171 typedef Tl allocator_type;
172 typedef std::map<key_type, value_type, compare_function, allocator_type> type;
175 typedef allocator_policies<pair_type, Thread> allocator_types;
176 typedef typename allocator_types::type allocator_typelist;
177 typedef typename transform<allocator_typelist, container>::type type;
180 template<typename Tp, bool Thread>
181 struct unordered_maps
183 typedef Tp value_type;
184 typedef Tp key_type;
185 typedef std::pair<const key_type, value_type> pair_type;
186 typedef std::tr1::hash<key_type> hash_function;
187 typedef std::equal_to<key_type> equality_function;
189 template<typename Tl>
190 struct container
192 typedef Tl allocator_type;
193 typedef std::tr1::unordered_map<key_type, value_type, hash_function, equality_function, allocator_type> type;
196 typedef allocator_policies<pair_type, Thread> allocator_types;
197 typedef typename allocator_types::type allocator_typelist;
198 typedef typename transform<allocator_typelist, container>::type type;
201 template<typename Tp, bool Thread>
202 struct sets
204 typedef Tp value_type;
205 typedef Tp key_type;
206 typedef std::less<key_type> compare_function;
208 template<typename Tl>
209 struct container
211 typedef Tl allocator_type;
212 typedef std::set<key_type, compare_function, allocator_type> type;
215 typedef allocator_policies<key_type, Thread> allocator_types;
216 typedef typename allocator_types::type allocator_typelist;
217 typedef typename transform<allocator_typelist, container>::type type;
220 template<typename Tp, bool Thread>
221 struct unordered_sets
223 typedef Tp value_type;
224 typedef Tp key_type;
225 typedef std::tr1::hash<key_type> hash_function;
226 typedef std::equal_to<key_type> equality_function;
228 template<typename Tl>
229 struct container
231 typedef Tl allocator_type;
232 typedef std::tr1::unordered_set<key_type, hash_function, equality_function, allocator_type> type;
235 typedef allocator_policies<key_type, Thread> allocator_types;
236 typedef typename allocator_types::type allocator_typelist;
237 typedef typename transform<allocator_typelist, container>::type type;
241 // A typelist of all associated container types, with each of the
242 // allocator policies.
243 template<typename Tp, bool Thread>
244 struct associative_containers
246 typedef Tp value_type;
248 typedef typename maps<value_type, Thread>::type map_typelist;
249 typedef typename sets<value_type, Thread>::type set_typelist;
250 typedef typename unordered_maps<value_type, Thread>::type unordered_map_typelist;
251 typedef typename unordered_sets<value_type, Thread>::type unordered_set_typelist;
253 typedef typename append<map_typelist, unordered_map_typelist>::type a1;
254 typedef typename append<set_typelist, unordered_set_typelist>::type a2;
255 typedef typename append<a1, a2>::type type;
258 // A typelist of all integral types.
259 struct integral_types
261 typedef bool a1;
262 typedef char a2;
263 typedef signed char a3;
264 typedef unsigned char a4;
265 typedef short a5;
266 typedef unsigned short a6;
267 typedef int a7;
268 typedef unsigned int a8;
269 typedef long a9;
270 typedef unsigned long a10;
271 typedef long long a11;
272 typedef unsigned long long a12;
273 typedef wchar_t a13;
274 #ifdef __GXX_EXPERIMENTAL_CXX0X__
275 typedef char16_t a14;
276 typedef char32_t a15;
278 typedef node<_GLIBCXX_TYPELIST_CHAIN15(a1, a2, a3, a4, a5, a6, a7, a8, a9,
279 a10, a11, a12, a13, a14, a15)> type;
280 #else
281 typedef node<_GLIBCXX_TYPELIST_CHAIN13(a1, a2, a3, a4, a5, a6, a7, a8, a9,
282 a10, a11, a12, a13)> type;
283 #endif
286 #ifdef __GXX_EXPERIMENTAL_CXX0X__
287 struct atomic_integrals_no_bool
289 typedef std::atomic_char a2;
290 typedef std::atomic_schar a3;
291 typedef std::atomic_uchar a4;
292 typedef std::atomic_short a5;
293 typedef std::atomic_ushort a6;
294 typedef std::atomic_int a7;
295 typedef std::atomic_uint a8;
296 typedef std::atomic_long a9;
297 typedef std::atomic_ulong a10;
298 typedef std::atomic_llong a11;
299 typedef std::atomic_ullong a12;
300 typedef std::atomic_wchar_t a13;
301 typedef std::atomic_char16_t a14;
302 typedef std::atomic_char32_t a15;
304 typedef node<_GLIBCXX_TYPELIST_CHAIN14(a2, a3, a4, a5, a6, a7, a8, a9,
305 a10, a11, a12, a13, a14, a15)> type;
308 struct atomic_integrals
310 typedef std::atomic_bool a1;
311 typedef std::atomic_char a2;
312 typedef std::atomic_schar a3;
313 typedef std::atomic_uchar a4;
314 typedef std::atomic_short a5;
315 typedef std::atomic_ushort a6;
316 typedef std::atomic_int a7;
317 typedef std::atomic_uint a8;
318 typedef std::atomic_long a9;
319 typedef std::atomic_ulong a10;
320 typedef std::atomic_llong a11;
321 typedef std::atomic_ullong a12;
322 typedef std::atomic_wchar_t a13;
323 typedef std::atomic_char16_t a14;
324 typedef std::atomic_char32_t a15;
326 typedef node<_GLIBCXX_TYPELIST_CHAIN15(a1, a2, a3, a4, a5, a6, a7, a8, a9,
327 a10, a11, a12, a13, a14, a15)> type;
331 template<typename Tp>
332 struct atomics
334 typedef Tp value_type;
335 typedef std::atomic<value_type> type;
338 typedef transform<integral_types::type, atomics>::type atomics_tl;
339 #endif
342 struct has_increment_operators
344 template<typename _Tp>
345 void
346 operator()()
348 struct _Concept
350 void __constraint()
352 _Tp a;
353 ++a; // prefix
354 a++; // postfix
355 a += a;
359 void (_Concept::*__x)() __attribute__((unused))
360 = &_Concept::__constraint;
364 struct has_decrement_operators
366 template<typename _Tp>
367 void
368 operator()()
370 struct _Concept
372 void __constraint()
374 _Tp a;
375 --a; // prefix
376 a--; // postfix
377 a -= a;
381 void (_Concept::*__x)() __attribute__((unused))
382 = &_Concept::__constraint;
386 template<typename _Tp>
387 void
388 bitwise_operators()
390 _Tp a = _Tp();
391 _Tp b = _Tp();
392 a | b;
393 a & b;
394 a ^ b;
398 template<typename _Tp>
399 void
400 bitwise_assignment_operators()
402 _Tp a = _Tp();
403 _Tp b = _Tp();
404 a |= b; // set
405 a &= ~b; // clear
406 a ^= b;
409 // 17.3.2.1.2 - Bitmask types [lib.bitmask.types]
410 // bitmask_operators
411 template<typename _BitmTp>
412 void
413 bitmask_operators()
415 bitwise_operators<_BitmTp>();
416 bitwise_assignment_operators<_BitmTp>();
419 struct has_bitwise_operators
421 template<typename _Tp>
422 void
423 operator()()
425 struct _Concept
427 void __constraint()
429 _Tp a;
430 _Tp b;
431 a |= b; // set
432 a &= ~b; // clear
433 a ^= b;
437 void (_Concept::*__x)() __attribute__((unused))
438 = &_Concept::__constraint;
442 // Generator to test standard layout
443 #ifdef __GXX_EXPERIMENTAL_CXX0X__
444 struct has_trivial_cons_dtor
446 template<typename _Tp>
447 void
448 operator()()
450 struct _Concept
452 void __constraint()
454 typedef std::has_trivial_default_constructor<_Tp> ctor_p;
455 static_assert(ctor_p::value, "default constructor not trivial");
457 typedef std::has_trivial_destructor<_Tp> dtor_p;
458 static_assert(dtor_p::value, "destructor not trivial");
462 void (_Concept::*__x)() __attribute__((unused))
463 = &_Concept::__constraint;
467 struct standard_layout
469 template<typename _Tp>
470 void
471 operator()()
473 struct _Concept
475 void __constraint()
477 // libstdc++/37907
478 // typedef std::is_standard_layout<_Tp> standard_layout_p;
479 // static_assert(standard_layout_p::value, "not standard_layout");
481 typedef std::has_virtual_destructor<_Tp> ctor_p;
482 static_assert(!ctor_p::value, "has virtual destructor");
486 void (_Concept::*__x)() __attribute__((unused))
487 = &_Concept::__constraint;
490 #endif
492 // Generator to test base class
493 struct has_required_base_class
495 template<typename _TBase, typename _TDerived>
496 void
497 operator()()
499 struct _Concept
501 void __constraint()
503 const _TDerived& obj = __a;
504 const _TBase* base __attribute__((unused)) = &obj;
507 _TDerived __a;
510 void (_Concept::*__x)() __attribute__((unused))
511 = &_Concept::__constraint;
515 // Generator to test assignment operator.
516 struct assignable
518 template<typename _Tp>
519 void
520 operator()()
522 struct _Concept
524 void __constraint()
525 { __v1 = __v2; }
527 _Tp __v1;
528 _Tp __v2;
531 void (_Concept::*__x)() __attribute__((unused))
532 = &_Concept::__constraint;
536 // Generator to test default constructor.
537 struct default_constructible
539 template<typename _Tp>
540 void
541 operator()()
543 struct _Concept
545 void __constraint()
546 { _Tp __v; }
549 void (_Concept::*__x)() __attribute__((unused))
550 = &_Concept::__constraint;
554 // Generator to test copy constructor.
555 struct copy_constructible
557 template<typename _Tp>
558 void
559 operator()()
561 struct _Concept
563 void __constraint()
564 { _Tp __v2(__v1); }
566 _Tp __v1;
569 void (_Concept::*__x)() __attribute__((unused))
570 = &_Concept::__constraint;
574 // Generator to test direct initialization, single value constructor.
575 struct single_value_constructible
577 template<typename _Ttype, typename _Tvalue>
578 void
579 operator()()
581 struct _Concept
583 void __constraint()
584 { _Ttype __v(__a); }
586 _Tvalue __a;
589 void (_Concept::*__x)() __attribute__((unused))
590 = &_Concept::__constraint;
594 // Generator to test direct list initialization
595 #ifdef __GXX_EXPERIMENTAL_CXX0X__
596 struct direct_list_initializable
598 template<typename _Ttype, typename _Tvalue>
599 void
600 operator()()
602 struct _Concept
604 void __constraint()
606 _Ttype __v1 { }; // default ctor
607 _Ttype __v2 { __a }; // single-argument ctor
610 _Tvalue __a;
613 void (_Concept::*__x)() __attribute__((unused))
614 = &_Concept::__constraint;
617 #endif
619 // Generator to test copy list initialization, aggregate initialization
620 struct copy_list_initializable
622 template<typename _Ttype, typename _Tvalue>
623 void
624 operator()()
626 struct _Concept
628 void __constraint()
629 { _Ttype __v = {__a}; }
631 _Tvalue __a;
634 void (_Concept::*__x)() __attribute__((unused))
635 = &_Concept::__constraint;
639 // Generator to test integral conversion operator
640 struct integral_convertable
642 template<typename _Ttype, typename _Tvalue>
643 void
644 operator()()
646 struct _Concept
648 void __constraint()
650 _Tvalue __v0(0);
651 _Tvalue __v1(1);
652 _Ttype __a(__v1);
653 __v0 = __a;
655 bool test __attribute__((unused)) = true;
656 VERIFY( __v1 == __v0 );
660 void (_Concept::*__x)() __attribute__((unused))
661 = &_Concept::__constraint;
665 // Generator to test integral assignment operator
666 struct integral_assignable
668 template<typename _Ttype, typename _Tvalue>
669 void
670 operator()()
672 struct _Concept
674 void __constraint()
676 _Tvalue __v0(0);
677 _Tvalue __v1(1);
678 _Ttype __a(__v0);
679 __a = __v1;
680 _Tvalue __vr = __a;
682 bool test __attribute__((unused)) = true;
683 VERIFY( __v1 == __vr );
687 void (_Concept::*__x)() __attribute__((unused))
688 = &_Concept::__constraint;
691 } // namespace __gnu_test
692 #endif