3 // Copyright (C) 2009 Free Software Foundation, Inc.
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
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.
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/>.
20 #ifndef _GLIBCXX_TESTSUITE_CONTAINERS_H
21 #define _GLIBCXX_TESTSUITE_CONTAINERS_H
24 #include <testsuite_container_traits.h>
26 // Container requirement testing.
29 // Compile-time typedef testing.
30 template<typename _Tp, bool _Bt = traits<_Tp>::is_container::value>
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;
44 // Conditional typedef testing, positive.
45 template<typename _Tp, bool _Bt = traits<_Tp>::is_reversible::value>
46 struct reversible_types
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;
54 template<typename _Tp, bool _Bt = traits<_Tp>::is_allocator_aware::value>
55 struct allocator_aware_types
57 // Allocator-aware requirements (table 82)
58 typedef _Tp test_type;
59 typedef typename test_type::allocator_type allocator_type;
62 template<typename _Tp, bool _Bt = traits<_Tp>::is_pointer_aware::value>
63 struct pointer_aware_types
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;
71 template<typename _Tp, bool _Bt = traits<_Tp>::is_associative::value>
72 struct associative_types
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;
81 template<typename _Tp, bool = traits<_Tp>::is_unordered::value>
82 struct unordered_types
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;
93 template<typename _Tp, bool _Bt = traits<_Tp>::is_mapped::value>
96 typedef _Tp test_type;
97 typedef typename test_type::mapped_type mapped_type;
100 template<typename _Tp, bool = traits<_Tp>::is_adaptor::value>
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;
112 // Conditional typedef testing, negative.
113 template<typename _Tp>
114 struct basic_types<_Tp, false> { };
116 template<typename _Tp>
117 struct reversible_types<_Tp, false> { };
119 template<typename _Tp>
120 struct allocator_aware_types<_Tp, false> { };
122 template<typename _Tp>
123 struct pointer_aware_types<_Tp, false> { };
125 template<typename _Tp>
126 struct associative_types<_Tp, false> { };
128 template<typename _Tp>
129 struct unordered_types<_Tp, false> { };
131 template<typename _Tp>
132 struct mapped_types<_Tp, false> { };
134 template<typename _Tp>
135 struct adaptor_types<_Tp, false> { };
138 template<typename _Tp>
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>
146 // Run-time test for constant_iterator requirements.
147 template<typename _Tp, bool = traits<_Tp>::is_allocator_aware::value>
150 populate(_Tp& container)
152 typename _Tp::value_type v;
153 container.insert(container.begin(), v);
154 container.insert(container.begin(), v);
158 template<typename _Tp>
159 struct populate<_Tp, false>
161 populate(_Tp& container) { }
164 template<typename _Tp, bool = traits<_Tp>::is_reversible::value>
165 struct reverse_members
167 reverse_members(_Tp& container)
169 assert( container.crbegin() == container.rbegin() );
170 assert( container.crend() == container.rend() );
171 assert( container.crbegin() != container.crend() );
175 template<typename _Tp>
176 struct reverse_members<_Tp, false>
178 reverse_members(_Tp& container) { }
182 template<typename _Tp, bool = traits<_Tp>::is_unordered::value>
183 struct forward_members_unordered
185 forward_members_unordered(typename _Tp::value_type& v)
187 typedef _Tp test_type;
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) );
197 template<typename _Tp>
198 struct forward_members_unordered<_Tp, false>
200 forward_members_unordered(_Tp& container) { }
203 template<typename _Tp>
206 typedef _Tp test_type;
207 typedef traits<test_type> traits_type;
208 typedef typename test_type::value_type value_type;
210 static test_type _S_container;
213 struct forward_members
217 assert( _S_container.cbegin() == _S_container.begin() );
218 assert( _S_container.cend() == _S_container.end() );
219 assert( _S_container.cbegin() != _S_container.cend() );
226 populate<test_type> p(_S_container);
228 reverse_members<test_type> m2(_S_container);
232 template<typename _Tp>
233 _Tp citerator<_Tp>::_S_container;
236 } // namespace __gnu_test