2 // typelist for the C++ library testsuite.
4 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010
5 // Free Software Foundation, Inc.
7 // This file is part of the GNU ISO C++ Library. This library is free
8 // software; you can redistribute it and/or modify it under the
9 // terms of the GNU General Public License as published by the
10 // Free Software Foundation; either version 3, or (at your option)
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License along
19 // with this library; see the file COPYING3. If not see
20 // <http://www.gnu.org/licenses/>.
23 #ifndef _TESTSUITE_COMMON_TYPES_H
24 #define _TESTSUITE_COMMON_TYPES_H 1
26 #include <ext/typelist.h>
28 #include <ext/new_allocator.h>
29 #include <ext/malloc_allocator.h>
30 #include <ext/mt_allocator.h>
31 #include <ext/bitmap_allocator.h>
32 #include <ext/pool_allocator.h>
43 #include <tr1/functional>
44 #include <tr1/unordered_map>
45 #include <tr1/unordered_set>
47 #ifdef __GXX_EXPERIMENTAL_CXX0X__
49 #include <type_traits>
54 using __gnu_cxx::typelist::node;
55 using __gnu_cxx::typelist::transform;
56 using __gnu_cxx::typelist::append;
58 // All the allocators to test.
59 template<typename Tp, bool Thread>
60 struct allocator_policies
62 typedef Tp value_type;
63 typedef __gnu_cxx::new_allocator<Tp> a1;
64 typedef __gnu_cxx::malloc_allocator<Tp> a2;
65 typedef __gnu_cxx::__common_pool_policy<__gnu_cxx::__pool, Thread> pool_policy;
66 typedef __gnu_cxx::__mt_alloc<Tp, pool_policy> a3;
67 typedef __gnu_cxx::bitmap_allocator<Tp> a4;
68 typedef __gnu_cxx::__pool_alloc<Tp> a5;
69 typedef node<_GLIBCXX_TYPELIST_CHAIN5(a1, a2, a3, a4, a5)> type;
72 // Typelists for vector, string, list, deque.
73 // XXX should just use template templates
74 template<typename Tp, bool Thread>
77 typedef Tp value_type;
82 typedef Tl allocator_type;
83 typedef std::vector<value_type, allocator_type> type;
86 typedef allocator_policies<value_type, Thread> allocator_types;
87 typedef typename allocator_types::type allocator_typelist;
88 typedef typename transform<allocator_typelist, vector_shell>::type type;
91 template<typename Tp, bool Thread>
94 typedef Tp value_type;
99 typedef Tl allocator_type;
100 typedef std::list<value_type, allocator_type> type;
103 typedef allocator_policies<value_type, Thread> allocator_types;
104 typedef typename allocator_types::type allocator_typelist;
105 typedef typename transform<allocator_typelist, list_shell>::type type;
108 template<typename Tp, bool Thread>
111 typedef Tp value_type;
113 template<typename Tl>
116 typedef Tl allocator_type;
117 typedef std::deque<value_type, allocator_type> type;
120 typedef allocator_policies<value_type, Thread> allocator_types;
121 typedef typename allocator_types::type allocator_typelist;
122 typedef typename transform<allocator_typelist, deque_shell>::type type;
125 template<typename Tp, bool Thread>
128 typedef Tp value_type;
130 template<typename Tl>
133 typedef Tl allocator_type;
134 typedef std::char_traits<value_type> traits_type;
135 typedef std::basic_string<value_type, traits_type, allocator_type> type;
138 typedef allocator_policies<value_type, Thread> allocator_types;
139 typedef typename allocator_types::type allocator_typelist;
140 typedef typename transform<allocator_typelist, string_shell>::type type;
143 // A typelist of vector, list, deque, and string all instantiated
144 // with each of the allocator policies.
145 template<typename Tp, bool Thread>
146 struct sequence_containers
148 typedef Tp value_type;
150 typedef typename vectors<value_type, Thread>::type vector_typelist;
151 typedef typename lists<value_type, Thread>::type list_typelist;
152 typedef typename deques<value_type, Thread>::type deque_typelist;
153 typedef typename strings<value_type, Thread>::type string_typelist;
155 typedef typename append<vector_typelist, list_typelist>::type a1;
156 typedef typename append<deque_typelist, string_typelist>::type a2;
157 typedef typename append<a1, a2>::type type;
160 // Typelists for map, set, unordered_set, unordered_map.
161 template<typename Tp, bool Thread>
164 typedef Tp value_type;
166 typedef std::pair<const key_type, value_type> pair_type;
167 typedef std::less<key_type> compare_function;
169 template<typename Tl>
172 typedef Tl allocator_type;
173 typedef std::map<key_type, value_type, compare_function, allocator_type> type;
176 typedef allocator_policies<pair_type, Thread> allocator_types;
177 typedef typename allocator_types::type allocator_typelist;
178 typedef typename transform<allocator_typelist, container>::type type;
181 template<typename Tp, bool Thread>
182 struct unordered_maps
184 typedef Tp value_type;
186 typedef std::pair<const key_type, value_type> pair_type;
187 typedef std::tr1::hash<key_type> hash_function;
188 typedef std::equal_to<key_type> equality_function;
190 template<typename Tl>
193 typedef Tl allocator_type;
194 typedef std::tr1::unordered_map<key_type, value_type, hash_function, equality_function, allocator_type> type;
197 typedef allocator_policies<pair_type, Thread> allocator_types;
198 typedef typename allocator_types::type allocator_typelist;
199 typedef typename transform<allocator_typelist, container>::type type;
202 template<typename Tp, bool Thread>
205 typedef Tp value_type;
207 typedef std::less<key_type> compare_function;
209 template<typename Tl>
212 typedef Tl allocator_type;
213 typedef std::set<key_type, compare_function, allocator_type> type;
216 typedef allocator_policies<key_type, Thread> allocator_types;
217 typedef typename allocator_types::type allocator_typelist;
218 typedef typename transform<allocator_typelist, container>::type type;
221 template<typename Tp, bool Thread>
222 struct unordered_sets
224 typedef Tp value_type;
226 typedef std::tr1::hash<key_type> hash_function;
227 typedef std::equal_to<key_type> equality_function;
229 template<typename Tl>
232 typedef Tl allocator_type;
233 typedef std::tr1::unordered_set<key_type, hash_function, equality_function, allocator_type> type;
236 typedef allocator_policies<key_type, Thread> allocator_types;
237 typedef typename allocator_types::type allocator_typelist;
238 typedef typename transform<allocator_typelist, container>::type type;
242 // A typelist of all associated container types, with each of the
243 // allocator policies.
244 template<typename Tp, bool Thread>
245 struct associative_containers
247 typedef Tp value_type;
249 typedef typename maps<value_type, Thread>::type map_typelist;
250 typedef typename sets<value_type, Thread>::type set_typelist;
251 typedef typename unordered_maps<value_type, Thread>::type unordered_map_typelist;
252 typedef typename unordered_sets<value_type, Thread>::type unordered_set_typelist;
254 typedef typename append<map_typelist, unordered_map_typelist>::type a1;
255 typedef typename append<set_typelist, unordered_set_typelist>::type a2;
256 typedef typename append<a1, a2>::type type;
259 // A typelist of all integral types.
260 struct integral_types
264 typedef signed char a3;
265 typedef unsigned char a4;
267 typedef unsigned short a6;
269 typedef unsigned int a8;
271 typedef unsigned long a10;
272 typedef long long a11;
273 typedef unsigned long long a12;
275 #ifdef __GXX_EXPERIMENTAL_CXX0X__
276 typedef char16_t a14;
277 typedef char32_t a15;
279 typedef node<_GLIBCXX_TYPELIST_CHAIN15(a1, a2, a3, a4, a5, a6, a7, a8, a9,
280 a10, a11, a12, a13, a14, a15)> type;
282 typedef node<_GLIBCXX_TYPELIST_CHAIN13(a1, a2, a3, a4, a5, a6, a7, a8, a9,
283 a10, a11, a12, a13)> type;
287 #ifdef __GXX_EXPERIMENTAL_CXX0X__
288 struct atomic_integrals_no_bool
290 typedef std::atomic_char a2;
291 typedef std::atomic_schar a3;
292 typedef std::atomic_uchar a4;
293 typedef std::atomic_short a5;
294 typedef std::atomic_ushort a6;
295 typedef std::atomic_int a7;
296 typedef std::atomic_uint a8;
297 typedef std::atomic_long a9;
298 typedef std::atomic_ulong a10;
299 typedef std::atomic_llong a11;
300 typedef std::atomic_ullong a12;
301 typedef std::atomic_wchar_t a13;
302 typedef std::atomic_char16_t a14;
303 typedef std::atomic_char32_t a15;
305 typedef node<_GLIBCXX_TYPELIST_CHAIN14(a2, a3, a4, a5, a6, a7, a8, a9,
306 a10, a11, a12, a13, a14, a15)> type;
309 struct atomic_integrals
311 typedef std::atomic_bool a1;
312 typedef std::atomic_char a2;
313 typedef std::atomic_schar a3;
314 typedef std::atomic_uchar a4;
315 typedef std::atomic_short a5;
316 typedef std::atomic_ushort a6;
317 typedef std::atomic_int a7;
318 typedef std::atomic_uint a8;
319 typedef std::atomic_long a9;
320 typedef std::atomic_ulong a10;
321 typedef std::atomic_llong a11;
322 typedef std::atomic_ullong a12;
323 typedef std::atomic_wchar_t a13;
324 typedef std::atomic_char16_t a14;
325 typedef std::atomic_char32_t a15;
327 typedef node<_GLIBCXX_TYPELIST_CHAIN15(a1, a2, a3, a4, a5, a6, a7, a8, a9,
328 a10, a11, a12, a13, a14, a15)> type;
332 template<typename Tp>
335 typedef Tp value_type;
336 typedef std::atomic<value_type> type;
339 typedef transform<integral_types::type, atomics>::type atomics_tl;
342 template<typename Tp>
343 struct numeric_limits
345 typedef Tp value_type;
346 typedef std::numeric_limits<value_type> type;
349 typedef transform<integral_types::type, numeric_limits>::type limits_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 #ifdef __GXX_EXPERIMENTAL_CXX0X__
396 template<typename _Tp>
398 constexpr_bitwise_operators()
400 constexpr _Tp a = _Tp();
401 constexpr _Tp b = _Tp();
402 constexpr _Tp c1 __attribute__((unused)) = a | b;
403 constexpr _Tp c2 __attribute__((unused)) = a & b;
404 constexpr _Tp c3 __attribute__((unused)) = a ^ b;
405 constexpr _Tp c4 __attribute__((unused)) = ~b;
409 template<typename _Tp>
421 template<typename _Tp>
423 bitwise_assignment_operators()
432 // 17.3.2.1.2 - Bitmask types [lib.bitmask.types]
434 template<typename _BitmTp>
438 bitwise_operators<_BitmTp>();
439 bitwise_assignment_operators<_BitmTp>();
442 struct has_bitwise_operators
444 template<typename _Tp>
460 void (_Concept::*__x)() __attribute__((unused))
461 = &_Concept::__constraint;
465 // Generator to test standard layout
466 #ifdef __GXX_EXPERIMENTAL_CXX0X__
467 struct has_trivial_cons_dtor
469 template<typename _Tp>
477 typedef std::has_trivial_default_constructor<_Tp> ctor_p;
478 static_assert(ctor_p::value, "default constructor not trivial");
480 typedef std::has_trivial_destructor<_Tp> dtor_p;
481 static_assert(dtor_p::value, "destructor not trivial");
485 void (_Concept::*__x)() __attribute__((unused))
486 = &_Concept::__constraint;
490 struct standard_layout
492 template<typename _Tp>
500 typedef std::is_standard_layout<_Tp> standard_layout_p;
501 static_assert(standard_layout_p::value, "not standard_layout");
505 void (_Concept::*__x)() __attribute__((unused))
506 = &_Concept::__constraint;
511 // Generator to test base class
512 struct has_required_base_class
514 template<typename _TBase, typename _TDerived>
522 const _TDerived& obj = __a;
523 const _TBase* base __attribute__((unused)) = &obj;
529 void (_Concept::*__x)() __attribute__((unused))
530 = &_Concept::__constraint;
534 // Generator to test assignment operator.
537 template<typename _Tp>
550 void (_Concept::*__x)() __attribute__((unused))
551 = &_Concept::__constraint;
555 // Generator to test default constructor.
556 struct default_constructible
558 template<typename _Tp>
565 { _Tp __v __attribute__((unused)); }
568 void (_Concept::*__x)() __attribute__((unused))
569 = &_Concept::__constraint;
573 // Generator to test copy constructor.
574 struct copy_constructible
576 template<typename _Tp>
588 void (_Concept::*__x)() __attribute__((unused))
589 = &_Concept::__constraint;
593 // Generator to test direct initialization, single value constructor.
594 struct single_value_constructible
596 template<typename _Ttype, typename _Tvalue>
608 void (_Concept::*__x)() __attribute__((unused))
609 = &_Concept::__constraint;
613 // Generator to test constexpr constructor
614 #ifdef __GXX_EXPERIMENTAL_CXX0X__
615 // Generator to test default constructor.
616 struct constexpr_default_constructible
618 template<typename _Tp>
624 // Have to have user-defined default ctor for this to work.
626 { constexpr _Tp __v; }
629 void (_Concept::*__x)() __attribute__((unused))
630 = &_Concept::__constraint;
634 struct constexpr_single_value_constructible
636 template<typename _Ttesttype, typename _Tbasetype>
642 // Additional constraint on _Tbasetype needed.
643 // Either assume user-defined default ctor as per
644 // constexpr_default_constructible and provide no
645 // initializer, provide an initializer, or assume empty-list
646 // init-able. Choose the latter.
649 constexpr _Tbasetype __v { };
650 constexpr _Ttesttype __t(__v);
660 // Generator to test direct list initialization
661 #ifdef __GXX_EXPERIMENTAL_CXX0X__
662 struct direct_list_initializable
664 template<typename _Ttype, typename _Tvalue>
672 _Ttype __v1 { }; // default ctor
673 _Ttype __v2 { __a }; // single-argument ctor
679 void (_Concept::*__x)() __attribute__((unused))
680 = &_Concept::__constraint;
685 // Generator to test copy list initialization, aggregate initialization
686 struct copy_list_initializable
688 template<typename _Ttype, typename _Tvalue>
695 { _Ttype __v __attribute__((unused)) = {__a}; }
700 void (_Concept::*__x)() __attribute__((unused))
701 = &_Concept::__constraint;
705 // Generator to test integral conversion operator
706 struct integral_convertable
708 template<typename _Ttype, typename _Tvalue>
721 bool test __attribute__((unused)) = true;
722 VERIFY( __v1 == __v0 );
726 void (_Concept::*__x)() __attribute__((unused))
727 = &_Concept::__constraint;
731 // Generator to test integral assignment operator
732 struct integral_assignable
734 template<typename _Ttype, typename _Tvalue>
748 bool test __attribute__((unused)) = true;
749 VERIFY( __v1 == __vr );
753 void (_Concept::*__x)() __attribute__((unused))
754 = &_Concept::__constraint;
757 } // namespace __gnu_test