3 // Copyright (C) 2009-2017 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::pointer pointer
;
37 typedef typename
test_type::const_pointer const_pointer
;
38 typedef typename
test_type::reference reference
;
39 typedef typename
test_type::const_reference const_reference
;
40 typedef typename
test_type::iterator iterator
;
41 typedef typename
test_type::const_iterator const_iterator
;
42 typedef typename
test_type::size_type size_type
;
43 typedef typename
test_type::difference_type difference_type
;
46 // Conditional typedef testing, positive.
47 template<typename _Tp
, bool _Bt
= traits
<_Tp
>::is_reversible::value
>
48 struct reversible_types
50 // Reversible container requirements (table 81)
51 typedef _Tp test_type
;
52 typedef typename
test_type::reverse_iterator reverse_iterator
;
53 typedef typename
test_type::const_reverse_iterator const_reverse_iterator
;
56 template<typename _Tp
, bool _Bt
= traits
<_Tp
>::is_allocator_aware::value
>
57 struct allocator_aware_types
59 // _Alloc-aware requirements (table 82)
60 typedef _Tp test_type
;
61 typedef typename
test_type::allocator_type allocator_type
;
64 template<typename _Tp
, bool _Bt
= traits
<_Tp
>::is_associative::value
>
65 struct associative_types
67 // Associative container requirements (table 85)
68 typedef _Tp test_type
;
69 typedef typename
test_type::key_type key_type
;
70 typedef typename
test_type::key_compare key_compare
;
71 typedef typename
test_type::value_compare value_compare
;
74 template<typename _Tp
, bool = traits
<_Tp
>::is_unordered::value
>
75 struct unordered_types
77 // Unordered associative container requirements (table 87)
78 typedef _Tp test_type
;
79 typedef typename
test_type::key_type key_type
;
80 typedef typename
test_type::hasher hasher
;
81 typedef typename
test_type::key_equal key_equal
;
82 typedef typename
test_type::local_iterator local_iterator
;
83 typedef typename
test_type::const_local_iterator const_local_iterator
;
86 template<typename _Tp
, bool _Bt
= traits
<_Tp
>::is_mapped::value
>
89 typedef _Tp test_type
;
90 typedef typename
test_type::mapped_type mapped_type
;
93 template<typename _Tp
, bool = traits
<_Tp
>::is_adaptor::value
>
96 // Container adaptor requirements.
97 typedef _Tp test_type
;
98 typedef typename
test_type::value_type value_type
;
99 typedef typename
test_type::reference reference
;
100 typedef typename
test_type::const_reference const_reference
;
101 typedef typename
test_type::size_type size_type
;
102 typedef typename
test_type::container_type container_type
;
105 // Conditional typedef testing, negative.
106 template<typename _Tp
>
107 struct basic_types
<_Tp
, false> { };
109 template<typename _Tp
>
110 struct adaptor_types
<_Tp
, false> { };
112 template<typename _Tp
>
113 struct reversible_types
<_Tp
, false> { };
115 template<typename _Tp
>
116 struct allocator_aware_types
<_Tp
, false> { };
118 template<typename _Tp
>
119 struct associative_types
<_Tp
, false> { };
121 template<typename _Tp
>
122 struct unordered_types
<_Tp
, false> { };
124 template<typename _Tp
>
125 struct mapped_types
<_Tp
, false> { };
128 template<typename _Tp
>
130 : basic_types
<_Tp
>, adaptor_types
<_Tp
>, reversible_types
<_Tp
>,
131 allocator_aware_types
<_Tp
>, associative_types
<_Tp
>,
132 unordered_types
<_Tp
>, mapped_types
<_Tp
>
136 // Run-time test for constant_iterator requirements.
137 template<typename _Tp
, bool = traits
<_Tp
>::is_allocator_aware::value
>
140 populate(_Tp
& container
)
142 // Avoid uninitialized warnings, requires DefaultContructible.
143 typedef typename
_Tp::value_type value_type
;
144 container
.insert(container
.begin(), value_type());
145 container
.insert(container
.begin(), value_type());
149 template<typename _Tp
>
150 struct populate
<_Tp
, false>
152 populate(_Tp
& container
) { }
155 template<typename _Tp
, bool = traits
<_Tp
>::is_reversible::value
>
156 struct reverse_members
158 reverse_members(_Tp
& container
)
160 assert( container
.crbegin() == container
.rbegin() );
161 assert( container
.crend() == container
.rend() );
162 assert( container
.crbegin() != container
.crend() );
166 template<typename _Tp
>
167 struct reverse_members
<_Tp
, false>
169 reverse_members(_Tp
& container
) { }
173 template<typename _Tp
, bool = traits
<_Tp
>::is_unordered::value
>
174 struct forward_members_unordered
176 forward_members_unordered(typename
_Tp::value_type
& v
)
178 typedef _Tp test_type
;
181 assert( container
.cbegin(0) == container
.begin(0) );
182 assert( container
.cend(0) == container
.end(0) );
183 const typename
test_type::size_type bn
= container
.bucket(1);
184 assert( container
.cbegin(bn
) != container
.cend(bn
) );
188 template<typename _Tp
>
189 struct forward_members_unordered
<_Tp
, false>
191 forward_members_unordered(_Tp
& container
) { }
194 template<typename _Tp
>
197 typedef _Tp test_type
;
198 typedef traits
<test_type
> traits_type
;
199 typedef typename
test_type::value_type value_type
;
201 static test_type _S_container
;
204 struct forward_members
208 assert( _S_container
.cbegin() == _S_container
.begin() );
209 assert( _S_container
.cend() == _S_container
.end() );
210 assert( _S_container
.cbegin() != _S_container
.cend() );
217 populate
<test_type
> p(_S_container
);
219 reverse_members
<test_type
> m2(_S_container
);
223 template<typename _Tp
>
224 _Tp citerator
<_Tp
>::_S_container
;
226 // DR 130 vs. C++98 vs. C++11.
227 // Defined in testsuite_shared.cc.
229 erase_external(std::set
<int>& s
);
232 erase_external(std::multiset
<int>& s
);
235 erase_external(std::map
<int, int>& s
);
238 erase_external(std::multimap
<int, int>& s
);
241 erase_external_iterators(std::set
<int>& s
);
244 erase_external_iterators(std::multiset
<int>& s
);
247 erase_external_iterators(std::map
<int, int>& s
);
250 erase_external_iterators(std::multimap
<int, int>& s
);
252 // NB: "must be compiled with C++11"
253 #if __cplusplus >= 201103L
254 template<typename _Tp
>
256 linkage_check_cxx98_cxx11_erase(_Tp
& container
)
258 // Crashing when external reference and internal reference symbols are
259 // equivalently mangled but have different size return types in C++98
260 // and C++11 signatures.
261 erase_external(container
); // C++98
262 container
.erase(container
.begin()); // C++11
265 template<typename _Tp
>
267 linkage_check_cxx98_cxx11_erase_iterators(_Tp
& container
)
269 // Crashing when external reference and internal reference symbols are
270 // equivalently mangled but have different size return types in C++98
271 // and C++11 signatures.
272 erase_external_iterators(container
);// C++98
274 auto iter
= container
.begin();
275 container
.erase(iter
, ++iter
); // C++11
279 } // namespace __gnu_test