OSDN Git Service

2008-05-05 Benjamin Kosnik <bkoz@redhat.com>
[pf3gnuchains/gcc-fork.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 #endif
58
59 namespace __gnu_test
60 {
61   using __gnu_cxx::typelist::node;
62   using __gnu_cxx::typelist::transform;
63   using __gnu_cxx::typelist::append;
64
65   // All the allocators to test.
66   template<typename Tp, bool Thread>
67     struct allocator_policies
68     {
69       typedef Tp                                value_type;
70       typedef __gnu_cxx::new_allocator<Tp>              a1;
71       typedef __gnu_cxx::malloc_allocator<Tp>           a2;
72       typedef __gnu_cxx::__common_pool_policy<__gnu_cxx::__pool, Thread> pool_policy;
73       typedef __gnu_cxx::__mt_alloc<Tp, pool_policy>    a3;
74       typedef __gnu_cxx::bitmap_allocator<Tp>           a4;
75       typedef __gnu_cxx::__pool_alloc<Tp>               a5;
76       typedef node<_GLIBCXX_TYPELIST_CHAIN5(a1, a2, a3, a4, a5)> type;
77     };
78
79   // Typelists for vector, string, list, deque.
80   // XXX should just use template templates
81   template<typename Tp, bool Thread>
82     struct vectors
83     {
84       typedef Tp                                        value_type;
85
86       template<typename Tl>
87         struct vector_shell
88         {
89           typedef Tl                                    allocator_type;
90           typedef std::vector<value_type, allocator_type>       type;
91         };
92
93       typedef allocator_policies<value_type, Thread>    allocator_types;
94       typedef typename allocator_types::type            allocator_typelist;
95       typedef typename transform<allocator_typelist, vector_shell>::type type;
96     };
97
98   template<typename Tp, bool Thread>
99     struct lists
100     {
101       typedef Tp                                        value_type;
102
103       template<typename Tl>
104         struct list_shell
105         {
106           typedef Tl                                    allocator_type;
107           typedef std::list<value_type, allocator_type> type;
108         };
109
110       typedef allocator_policies<value_type, Thread>    allocator_types;
111       typedef typename allocator_types::type            allocator_typelist;
112       typedef typename transform<allocator_typelist, list_shell>::type type;
113     };
114
115   template<typename Tp, bool Thread>
116     struct deques
117     {
118       typedef Tp                                        value_type;
119
120       template<typename Tl>
121         struct deque_shell
122         {
123           typedef Tl                                    allocator_type;
124           typedef std::deque<value_type, allocator_type>        type;
125         };
126
127       typedef allocator_policies<value_type, Thread>    allocator_types;
128       typedef typename allocator_types::type            allocator_typelist;
129       typedef typename transform<allocator_typelist, deque_shell>::type type;
130     };
131
132   template<typename Tp, bool Thread>
133     struct strings
134     {
135       typedef Tp                                        value_type;
136
137       template<typename Tl>
138         struct string_shell
139         {
140           typedef Tl                                    allocator_type;
141           typedef std::char_traits<value_type>          traits_type;
142           typedef std::basic_string<value_type, traits_type, allocator_type>    type;
143         };
144
145       typedef allocator_policies<value_type, Thread>    allocator_types;
146       typedef typename allocator_types::type            allocator_typelist;
147       typedef typename transform<allocator_typelist, string_shell>::type type;
148     };
149
150   // A typelist of vector, list, deque, and string all instantiated
151   // with each of the allocator policies.
152   template<typename Tp, bool Thread>
153     struct sequence_containers
154     {
155       typedef Tp                                        value_type;
156
157       typedef typename vectors<value_type, Thread>::type vector_typelist;
158       typedef typename lists<value_type, Thread>::type   list_typelist;
159       typedef typename deques<value_type, Thread>::type  deque_typelist;
160       typedef typename strings<value_type, Thread>::type string_typelist;
161
162       typedef typename append<vector_typelist, list_typelist>::type a1;
163       typedef typename append<deque_typelist, string_typelist>::type a2;
164       typedef typename append<a1, a2>::type type;
165     };
166
167   // Typelists for map, set, unordered_set, unordered_map.
168   template<typename Tp, bool Thread>
169     struct maps
170     {
171       typedef Tp                                        value_type;
172       typedef Tp                                        key_type;
173       typedef std::pair<const key_type, value_type>     pair_type;
174       typedef std::less<key_type>                       compare_function;
175
176       template<typename Tl>
177         struct container
178         {
179           typedef Tl                                    allocator_type;
180           typedef std::map<key_type, value_type, compare_function, allocator_type>      type;
181         };
182
183       typedef allocator_policies<pair_type, Thread>     allocator_types;
184       typedef typename allocator_types::type            allocator_typelist;
185       typedef typename transform<allocator_typelist, container>::type type;
186     };
187
188   template<typename Tp, bool Thread>
189     struct unordered_maps
190     {
191       typedef Tp                                        value_type;
192       typedef Tp                                        key_type;
193       typedef std::pair<const key_type, value_type>     pair_type;
194       typedef std::tr1::hash<key_type>                  hash_function;
195       typedef std::equal_to<key_type>                   equality_function;
196
197       template<typename Tl>
198         struct container
199         {
200           typedef Tl                                    allocator_type;
201           typedef std::tr1::unordered_map<key_type, value_type, hash_function, equality_function, allocator_type>       type;
202         };
203
204       typedef allocator_policies<pair_type, Thread>     allocator_types;
205       typedef typename allocator_types::type            allocator_typelist;
206       typedef typename transform<allocator_typelist, container>::type type;
207     };
208
209   template<typename Tp, bool Thread>
210     struct sets
211     {
212       typedef Tp                                        value_type;
213       typedef Tp                                        key_type;
214       typedef std::less<key_type>                       compare_function;
215
216       template<typename Tl>
217         struct container
218         {
219           typedef Tl                                    allocator_type;
220           typedef std::set<key_type, compare_function, allocator_type>  type;
221         };
222
223       typedef allocator_policies<key_type, Thread>      allocator_types;
224       typedef typename allocator_types::type            allocator_typelist;
225       typedef typename transform<allocator_typelist, container>::type type;
226     };
227
228   template<typename Tp, bool Thread>
229     struct unordered_sets
230     {
231       typedef Tp                                        value_type;
232       typedef Tp                                        key_type;
233       typedef std::tr1::hash<key_type>                  hash_function;
234       typedef std::equal_to<key_type>                   equality_function;
235
236       template<typename Tl>
237         struct container
238         {
239           typedef Tl                                    allocator_type;
240           typedef std::tr1::unordered_set<key_type, hash_function, equality_function, allocator_type>   type;
241         };
242
243       typedef allocator_policies<key_type, Thread>      allocator_types;
244       typedef typename allocator_types::type            allocator_typelist;
245       typedef typename transform<allocator_typelist, container>::type type;
246     };
247
248
249   // A typelist  of all associated  container types, with each  of the
250   // allocator policies.
251   template<typename Tp, bool Thread>
252     struct associative_containers
253     {
254       typedef Tp                                        value_type;
255
256       typedef typename maps<value_type, Thread>::type map_typelist;
257       typedef typename sets<value_type, Thread>::type set_typelist;
258       typedef typename unordered_maps<value_type, Thread>::type unordered_map_typelist;
259       typedef typename unordered_sets<value_type, Thread>::type unordered_set_typelist;
260
261       typedef typename append<map_typelist, unordered_map_typelist>::type a1;
262       typedef typename append<set_typelist, unordered_set_typelist>::type a2;
263       typedef typename append<a1, a2>::type type;
264     };
265
266   // A typelist of all integral types.
267   struct integral_types
268   {
269     typedef bool                a1;
270     typedef char                a2;
271     typedef signed char         a3;
272     typedef unsigned char       a4;
273     typedef short               a5;
274     typedef unsigned short      a6;
275     typedef int                 a7;
276     typedef unsigned int        a8;
277     typedef long                a9;
278     typedef unsigned long       a10;
279     typedef long long           a11;
280     typedef unsigned long long  a12;
281     typedef wchar_t             a13;
282     // typedef char16_t                 a14;
283     // typedef char16_t                 a15;
284
285     typedef node<_GLIBCXX_TYPELIST_CHAIN13(a1, a2, a3, a4, a5, a6, a7, a8, a9, 
286                                            a10, a11, a12, a13)> type;
287   };
288
289 #ifdef __GXX_EXPERIMENTAL_CXX0X__
290   template<typename Tp>
291     struct atomics
292     {
293       typedef Tp                        value_type;
294       typedef std::atomic<value_type>   type;
295     };
296
297   typedef transform<integral_types::type, atomics>::type atomics_tl;
298 #endif
299
300   // Generator to test assignment operator.
301   struct assignable
302   {
303     template<typename _T>
304       void 
305       operator()()
306       {
307         _T v1;
308         _T v2;
309         v1 = v2;
310       }
311   };
312
313   // Generator to test default constructor.
314   struct default_constructible
315   {
316     template<typename _T>
317       void 
318       operator()()
319       {
320         _T v;
321       }
322   };
323
324   // Generator to test copy constructor.
325   struct copy_constructible
326   {
327     template<typename _T>
328       void 
329       operator()()
330       {
331         _T v1;
332         _T v2(v1);
333       }
334   };
335
336   // Generator to test explicit value constructor.
337   struct explicit_value_constructible
338   {
339     template<typename _Ttype, typename _Tvalue>
340       void 
341       operator()()
342       {
343         _Tvalue a;
344         _Ttype v(a);
345       }
346   };
347
348 } // namespace __gnu_test
349 #endif