OSDN Git Service

2009-08-25 Benjamin Kosnik <bkoz@redhat.com>
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / testsuite / util / testsuite_containers.h
1 // -*- C++ -*-
2
3 // Copyright (C) 2009 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library.  This library is free
6 // software; you can redistribute it and/or modify it under the terms
7 // of the GNU General Public License as published by the Free Software
8 // Foundation; either version 3, or (at your option) any later
9 // version.
10
11 // This library is distributed in the hope that it will be useful, but
12 // WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // General Public License for more details.
15
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING3.  If not see
18 // <http://www.gnu.org/licenses/>.
19
20 #ifndef _GLIBCXX_TESTSUITE_CONTAINERS_H
21 #define _GLIBCXX_TESTSUITE_CONTAINERS_H
22
23 #include <cassert>
24 #include <testsuite_container_traits.h>
25
26 // Container requirement testing.
27 namespace __gnu_test
28 {
29   // Compile-time typedef testing.
30   template<typename _Tp, bool _Bt = traits<_Tp>::is_container::value>
31     struct basic_types
32     {
33       // Base container requirements (table 80)
34       typedef _Tp                                       test_type;
35       typedef typename test_type::value_type            value_type;
36       typedef typename test_type::reference             reference;
37       typedef typename test_type::const_reference       const_reference;
38       typedef typename test_type::iterator              iterator;
39       typedef typename test_type::const_iterator        const_iterator;
40       typedef typename test_type::size_type             size_type;
41       typedef typename test_type::difference_type       difference_type;
42     };
43
44   // Conditional typedef testing, positive.
45   template<typename _Tp, bool _Bt = traits<_Tp>::is_reversible::value>
46     struct reversible_types
47     {
48       // Reversible container requirements (table 81)
49       typedef _Tp                                        test_type;
50       typedef typename test_type::reverse_iterator       reverse_iterator;
51       typedef typename test_type::const_reverse_iterator const_reverse_iterator;
52     };
53
54   template<typename _Tp, bool _Bt = traits<_Tp>::is_allocator_aware::value>
55     struct allocator_aware_types
56     {
57       // Allocator-aware requirements (table 82)
58       typedef _Tp                                        test_type;
59       typedef typename test_type::allocator_type         allocator_type;
60     };
61
62   template<typename _Tp, bool _Bt = traits<_Tp>::is_pointer_aware::value>
63     struct pointer_aware_types
64     {
65       // Allocator-aware requirements (table 82)
66       typedef _Tp                                        test_type;
67       typedef typename test_type::pointer                pointer;
68       typedef typename test_type::const_pointer          const_pointer;
69     };
70
71   template<typename _Tp, bool _Bt = traits<_Tp>::is_associative::value>
72     struct associative_types
73     {
74       // Associative container requirements (table 85)
75       typedef _Tp                                        test_type;
76       typedef typename test_type::key_type               key_type;
77       typedef typename test_type::key_compare            key_compare;
78       typedef typename test_type::value_compare          value_compare;
79     };
80
81   template<typename _Tp, bool = traits<_Tp>::is_unordered::value>
82     struct unordered_types
83     {
84       // Unordered associative container requirements (table 87)
85       typedef _Tp                                        test_type;
86       typedef typename test_type::key_type               key_type;
87       typedef typename test_type::hasher                 hasher;
88       typedef typename test_type::key_equal              key_equal;
89       typedef typename test_type::local_iterator         local_iterator;
90       typedef typename test_type::const_local_iterator   const_local_iterator;
91     };
92
93   template<typename _Tp, bool _Bt = traits<_Tp>::is_mapped::value>
94     struct mapped_types
95     {
96       typedef _Tp                                        test_type;
97       typedef typename test_type::mapped_type            mapped_type;
98     };
99
100   template<typename _Tp, bool = traits<_Tp>::is_adaptor::value>
101     struct adaptor_types
102     {
103       // Container adaptor requirements.
104       typedef _Tp                                       test_type;
105       typedef typename test_type::value_type            value_type;
106       typedef typename test_type::reference             reference;
107       typedef typename test_type::const_reference       const_reference;
108       typedef typename test_type::size_type             size_type;
109       typedef typename test_type::container_type        container_type;
110     };
111
112   // Conditional typedef testing, negative.
113   template<typename _Tp>
114     struct basic_types<_Tp, false> { };
115
116   template<typename _Tp>
117     struct reversible_types<_Tp, false> { };
118
119   template<typename _Tp>
120     struct allocator_aware_types<_Tp, false> { };
121
122   template<typename _Tp>
123     struct pointer_aware_types<_Tp, false> { };
124
125   template<typename _Tp>
126     struct associative_types<_Tp, false> { };
127
128   template<typename _Tp>
129     struct unordered_types<_Tp, false> { };
130
131   template<typename _Tp>
132     struct mapped_types<_Tp, false> { };
133
134   template<typename _Tp>
135     struct adaptor_types<_Tp, false> { };
136
137   // Primary template.
138   template<typename _Tp>
139     struct types
140     : basic_types<_Tp>, adaptor_types<_Tp>, reversible_types<_Tp>,
141       allocator_aware_types<_Tp>, pointer_aware_types<_Tp>,
142       associative_types<_Tp>, unordered_types<_Tp>, mapped_types<_Tp>
143     { };
144
145
146   // Run-time test for constant_iterator requirements.
147   template<typename _Tp, bool = traits<_Tp>::is_allocator_aware::value>
148     struct populate
149     {
150       populate(_Tp& container)
151       {
152         typename _Tp::value_type v;
153         container.insert(container.begin(), v);
154         container.insert(container.begin(), v);
155       }
156   };
157
158   template<typename _Tp>
159     struct populate<_Tp, false>
160     {
161       populate(_Tp& container) { }
162     };
163
164   template<typename _Tp, bool = traits<_Tp>::is_reversible::value>
165     struct reverse_members
166     {
167       reverse_members(_Tp& container)
168       {
169         assert( container.crbegin() == container.rbegin() );
170         assert( container.crend() == container.rend() );
171         assert( container.crbegin() != container.crend() );
172       }
173     };
174
175   template<typename _Tp>
176     struct reverse_members<_Tp, false>
177     {
178       reverse_members(_Tp& container) { }
179     };
180
181   // DR 691.
182   template<typename _Tp, bool = traits<_Tp>::is_unordered::value>
183     struct forward_members_unordered
184     {
185       forward_members_unordered(typename _Tp::value_type& v)
186       {
187         typedef _Tp                                     test_type;
188         test_type container;
189         container.insert(v);
190         assert( container.cbegin(0) == container.begin(0) );
191         assert( container.cend(0) == container.end(0) );
192         const typename test_type::size_type bn = container.bucket(1);
193         assert( container.cbegin(bn) != container.cend(bn) );
194       }
195     };
196
197   template<typename _Tp>
198     struct forward_members_unordered<_Tp, false>
199     {
200       forward_members_unordered(_Tp& container) { }
201     };
202
203   template<typename _Tp>
204     struct citerator
205     {
206       typedef _Tp                                       test_type;
207       typedef traits<test_type>                         traits_type;
208       typedef typename test_type::value_type            value_type;
209
210       static test_type _S_container;
211
212       // Unconditional.
213       struct forward_members
214       {
215         forward_members()
216         {
217           assert( _S_container.cbegin() == _S_container.begin() );
218           assert( _S_container.cend() == _S_container.end() );
219           assert( _S_container.cbegin() != _S_container.cend() );
220         }
221       };
222
223       // Run test.
224       citerator()
225       {
226         populate<test_type> p(_S_container);
227         forward_members m1;
228         reverse_members<test_type> m2(_S_container);
229       }
230   };
231
232   template<typename _Tp>
233   _Tp citerator<_Tp>::_S_container;
234
235
236 } // namespace __gnu_test
237
238 #endif