2 // typelist for the C++ library testsuite.
4 // Copyright (C) 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
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)
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 COPYING. If not, write to the Free
19 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
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.
31 #ifndef _TESTSUITE_COMMON_TYPES_H
32 #define _TESTSUITE_COMMON_TYPES_H 1
34 #include <ext/typelist.h>
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>
51 #include <tr1/functional>
52 #include <tr1/unordered_map>
53 #include <tr1/unordered_set>
55 #ifdef __GXX_EXPERIMENTAL_CXX0X__
57 #include <type_traits>
62 using __gnu_cxx::typelist::node;
63 using __gnu_cxx::typelist::transform;
64 using __gnu_cxx::typelist::append;
66 // All the allocators to test.
67 template<typename Tp, bool Thread>
68 struct allocator_policies
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;
80 // Typelists for vector, string, list, deque.
81 // XXX should just use template templates
82 template<typename Tp, bool Thread>
85 typedef Tp value_type;
90 typedef Tl allocator_type;
91 typedef std::vector<value_type, allocator_type> type;
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;
99 template<typename Tp, bool Thread>
102 typedef Tp value_type;
104 template<typename Tl>
107 typedef Tl allocator_type;
108 typedef std::list<value_type, allocator_type> type;
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;
116 template<typename Tp, bool Thread>
119 typedef Tp value_type;
121 template<typename Tl>
124 typedef Tl allocator_type;
125 typedef std::deque<value_type, allocator_type> type;
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;
133 template<typename Tp, bool Thread>
136 typedef Tp value_type;
138 template<typename Tl>
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;
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;
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
156 typedef Tp value_type;
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;
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;
168 // Typelists for map, set, unordered_set, unordered_map.
169 template<typename Tp, bool Thread>
172 typedef Tp value_type;
174 typedef std::pair<const key_type, value_type> pair_type;
175 typedef std::less<key_type> compare_function;
177 template<typename Tl>
180 typedef Tl allocator_type;
181 typedef std::map<key_type, value_type, compare_function, allocator_type> type;
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;
189 template<typename Tp, bool Thread>
190 struct unordered_maps
192 typedef Tp value_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;
198 template<typename Tl>
201 typedef Tl allocator_type;
202 typedef std::tr1::unordered_map<key_type, value_type, hash_function, equality_function, allocator_type> type;
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;
210 template<typename Tp, bool Thread>
213 typedef Tp value_type;
215 typedef std::less<key_type> compare_function;
217 template<typename Tl>
220 typedef Tl allocator_type;
221 typedef std::set<key_type, compare_function, allocator_type> type;
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;
229 template<typename Tp, bool Thread>
230 struct unordered_sets
232 typedef Tp value_type;
234 typedef std::tr1::hash<key_type> hash_function;
235 typedef std::equal_to<key_type> equality_function;
237 template<typename Tl>
240 typedef Tl allocator_type;
241 typedef std::tr1::unordered_set<key_type, hash_function, equality_function, allocator_type> type;
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;
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
255 typedef Tp value_type;
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;
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;
267 // A typelist of all integral types.
268 struct integral_types
272 typedef signed char a3;
273 typedef unsigned char a4;
275 typedef unsigned short a6;
277 typedef unsigned int a8;
279 typedef unsigned long a10;
280 typedef long long a11;
281 typedef unsigned long long a12;
283 #ifdef __GXX_EXPERIMENTAL_CXX0X__
284 typedef char16_t a14;
285 typedef char32_t a15;
287 typedef node<_GLIBCXX_TYPELIST_CHAIN15(a1, a2, a3, a4, a5, a6, a7, a8, a9,
288 a10, a11, a12, a13, a14, a15)> type;
290 typedef node<_GLIBCXX_TYPELIST_CHAIN13(a1, a2, a3, a4, a5, a6, a7, a8, a9,
291 a10, a11, a12, a13)> type;
295 #ifdef __GXX_EXPERIMENTAL_CXX0X__
296 struct atomic_integrals_no_bool
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;
313 typedef node<_GLIBCXX_TYPELIST_CHAIN14(a2, a3, a4, a5, a6, a7, a8, a9,
314 a10, a11, a12, a13, a14, a15)> type;
317 struct atomic_integrals
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;
335 typedef node<_GLIBCXX_TYPELIST_CHAIN15(a1, a2, a3, a4, a5, a6, a7, a8, a9,
336 a10, a11, a12, a13, a14, a15)> type;
340 template<typename Tp>
343 typedef Tp value_type;
344 typedef std::atomic<value_type> type;
347 typedef transform<integral_types::type, atomics>::type atomics_tl;
351 struct has_increment_operators
353 template<typename _Tp>
368 void (_Concept::*__x)() __attribute__((unused))
369 = &_Concept::__constraint;
373 struct has_decrement_operators
375 template<typename _Tp>
390 void (_Concept::*__x)() __attribute__((unused))
391 = &_Concept::__constraint;
395 template<typename _Tp>
407 template<typename _Tp>
409 bitwise_assignment_operators()
418 // 17.3.2.1.2 - Bitmask types [lib.bitmask.types]
420 template<typename _BitmTp>
424 bitwise_operators<_BitmTp>();
425 bitwise_assignment_operators<_BitmTp>();
428 struct has_bitwise_operators
430 template<typename _Tp>
438 bitwise_assignment_operators<_Tp>();
442 void (_Concept::*__x)() __attribute__((unused))
443 = &_Concept::__constraint;
447 // Generator to test standard layout
448 #ifdef __GXX_EXPERIMENTAL_CXX0X__
449 struct has_trivial_cons_dtor
451 template<typename _Tp>
459 typedef std::has_trivial_default_constructor<_Tp> ctor_p;
460 static_assert(ctor_p::value, "default constructor not trivial");
462 typedef std::has_trivial_destructor<_Tp> dtor_p;
463 static_assert(dtor_p::value, "destructor not trivial");
467 void (_Concept::*__x)() __attribute__((unused))
468 = &_Concept::__constraint;
472 struct standard_layout
474 template<typename _Tp>
483 // typedef std::is_standard_layout<_Tp> standard_layout_p;
484 // static_assert(standard_layout_p::value, "not standard_layout");
486 typedef std::has_virtual_destructor<_Tp> ctor_p;
487 static_assert(!ctor_p::value, "has virtual destructor");
491 void (_Concept::*__x)() __attribute__((unused))
492 = &_Concept::__constraint;
497 // Generator to test base class
498 struct has_required_base_class
500 template<typename _TBase, typename _TDerived>
508 const _TDerived& obj = __a;
509 const _TBase* base __attribute__((unused)) = &obj;
515 void (_Concept::*__x)() __attribute__((unused))
516 = &_Concept::__constraint;
520 // Generator to test assignment operator.
523 template<typename _Tp>
536 void (_Concept::*__x)() __attribute__((unused))
537 = &_Concept::__constraint;
541 // Generator to test default constructor.
542 struct default_constructible
544 template<typename _Tp>
554 void (_Concept::*__x)() __attribute__((unused))
555 = &_Concept::__constraint;
559 // Generator to test copy constructor.
560 struct copy_constructible
562 template<typename _Tp>
574 void (_Concept::*__x)() __attribute__((unused))
575 = &_Concept::__constraint;
579 // Generator to test direct initialization, single value constructor.
580 struct single_value_constructible
582 template<typename _Ttype, typename _Tvalue>
594 void (_Concept::*__x)() __attribute__((unused))
595 = &_Concept::__constraint;
599 // Generator to test direct list initialization
600 #ifdef __GXX_EXPERIMENTAL_CXX0X__
601 struct direct_list_initializable
603 template<typename _Ttype, typename _Tvalue>
611 _Ttype __v1 { }; // default ctor
612 _Ttype __v2 { __a }; // single-argument ctor
618 void (_Concept::*__x)() __attribute__((unused))
619 = &_Concept::__constraint;
624 // Generator to test copy list initialization, aggregate initialization
625 struct copy_list_initializable
627 template<typename _Ttype, typename _Tvalue>
634 { _Ttype __v = {__a}; }
639 void (_Concept::*__x)() __attribute__((unused))
640 = &_Concept::__constraint;
644 // Generator to test integral conversion operator
645 struct integral_convertable
647 template<typename _Ttype, typename _Tvalue>
660 bool test __attribute__((unused)) = true;
661 VERIFY( __v1 == __v0 );
665 void (_Concept::*__x)() __attribute__((unused))
666 = &_Concept::__constraint;
670 // Generator to test integral assignment operator
671 struct integral_assignable
673 template<typename _Ttype, typename _Tvalue>
687 bool test __attribute__((unused)) = true;
688 VERIFY( __v1 == __vr );
692 void (_Concept::*__x)() __attribute__((unused))
693 = &_Concept::__constraint;
696 } // namespace __gnu_test