]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/include/debug/multiset.h
c++config: Add in revised namespace associations.
[thirdparty/gcc.git] / libstdc++-v3 / include / debug / multiset.h
1 // Debugging multiset implementation -*- C++ -*-
2
3 // Copyright (C) 2003, 2004, 2005
4 // 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 _GLIBCXX_DEBUG_MULTISET_H
32 #define _GLIBCXX_DEBUG_MULTISET_H 1
33
34 #include <debug/safe_sequence.h>
35 #include <debug/safe_iterator.h>
36 #include <utility>
37
38 namespace std
39 {
40 namespace __gnu_debug_def
41 {
42 template<typename _Key, typename _Compare = std::less<_Key>,
43 typename _Allocator = std::allocator<_Key> >
44 class multiset
45 : public _GLIBCXX_STD::multiset<_Key, _Compare, _Allocator>,
46 public __gnu_debug::_Safe_sequence<multiset<_Key, _Compare, _Allocator> >
47 {
48 typedef _GLIBCXX_STD::multiset<_Key, _Compare, _Allocator> _Base;
49 typedef __gnu_debug::_Safe_sequence<multiset> _Safe_base;
50
51 public:
52 // types:
53 typedef _Key key_type;
54 typedef _Key value_type;
55 typedef _Compare key_compare;
56 typedef _Compare value_compare;
57 typedef _Allocator allocator_type;
58 typedef typename _Base::reference reference;
59 typedef typename _Base::const_reference const_reference;
60
61 typedef __gnu_debug::_Safe_iterator<typename _Base::iterator, multiset>
62 iterator;
63 typedef __gnu_debug::_Safe_iterator<typename _Base::const_iterator,
64 multiset> const_iterator;
65
66 typedef typename _Base::size_type size_type;
67 typedef typename _Base::difference_type difference_type;
68 typedef typename _Base::pointer pointer;
69 typedef typename _Base::const_pointer const_pointer;
70 typedef std::reverse_iterator<iterator> reverse_iterator;
71 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
72
73 // 23.3.3.1 construct/copy/destroy:
74 explicit multiset(const _Compare& __comp = _Compare(),
75 const _Allocator& __a = _Allocator())
76 : _Base(__comp, __a) { }
77
78 template<typename _InputIterator>
79 multiset(_InputIterator __first, _InputIterator __last,
80 const _Compare& __comp = _Compare(),
81 const _Allocator& __a = _Allocator())
82 : _Base(__gnu_debug::__check_valid_range(__first, __last), __last,
83 __comp, __a) { }
84
85 multiset(const multiset<_Key,_Compare,_Allocator>& __x)
86 : _Base(__x), _Safe_base() { }
87
88 multiset(const _Base& __x) : _Base(__x), _Safe_base() { }
89
90 ~multiset() { }
91
92 multiset<_Key,_Compare,_Allocator>&
93 operator=(const multiset<_Key,_Compare,_Allocator>& __x)
94 {
95 *static_cast<_Base*>(this) = __x;
96 this->_M_invalidate_all();
97 return *this;
98 }
99
100 using _Base::get_allocator;
101
102 // iterators:
103 iterator
104 begin()
105 { return iterator(_Base::begin(), this); }
106
107 const_iterator
108 begin() const
109 { return const_iterator(_Base::begin(), this); }
110
111 iterator
112 end()
113 { return iterator(_Base::end(), this); }
114
115 const_iterator
116 end() const
117 { return const_iterator(_Base::end(), this); }
118
119 reverse_iterator
120 rbegin()
121 { return reverse_iterator(end()); }
122
123 const_reverse_iterator
124 rbegin() const
125 { return const_reverse_iterator(end()); }
126
127 reverse_iterator
128 rend()
129 { return reverse_iterator(begin()); }
130
131 const_reverse_iterator
132 rend() const
133 { return const_reverse_iterator(begin()); }
134
135 // capacity:
136 using _Base::empty;
137 using _Base::size;
138 using _Base::max_size;
139
140 // modifiers:
141 iterator
142 insert(const value_type& __x)
143 { return iterator(_Base::insert(__x), this); }
144
145 iterator
146 insert(iterator __position, const value_type& __x)
147 {
148 __glibcxx_check_insert(__position);
149 return iterator(_Base::insert(__position.base(), __x), this);
150 }
151
152 template<typename _InputIterator>
153 void
154 insert(_InputIterator __first, _InputIterator __last)
155 {
156 __glibcxx_check_valid_range(__first, __last);
157 _Base::insert(__first, __last);
158 }
159
160 void
161 erase(iterator __position)
162 {
163 __glibcxx_check_erase(__position);
164 __position._M_invalidate();
165 _Base::erase(__position.base());
166 }
167
168 size_type
169 erase(const key_type& __x)
170 {
171 std::pair<iterator, iterator> __victims = this->equal_range(__x);
172 size_type __count = 0;
173 while (__victims.first != __victims.second)
174 {
175 iterator __victim = __victims.first++;
176 __victim._M_invalidate();
177 _Base::erase(__victim.base());
178 ++__count;
179 }
180 return __count;
181 }
182
183 void
184 erase(iterator __first, iterator __last)
185 {
186 // _GLIBCXX_RESOLVE_LIB_DEFECTS
187 // 151. can't currently clear() empty container
188 __glibcxx_check_erase_range(__first, __last);
189 while (__first != __last)
190 this->erase(__first++);
191 }
192
193 void
194 swap(multiset<_Key,_Compare,_Allocator>& __x)
195 {
196 _Base::swap(__x);
197 this->_M_swap(__x);
198 }
199
200 void
201 clear()
202 { this->erase(begin(), end()); }
203
204 // observers:
205 using _Base::key_comp;
206 using _Base::value_comp;
207
208 // multiset operations:
209 iterator
210 find(const key_type& __x)
211 { return iterator(_Base::find(__x), this); }
212
213 // _GLIBCXX_RESOLVE_LIB_DEFECTS
214 // 214. set::find() missing const overload
215 const_iterator
216 find(const key_type& __x) const
217 { return const_iterator(_Base::find(__x), this); }
218
219 using _Base::count;
220
221 iterator
222 lower_bound(const key_type& __x)
223 { return iterator(_Base::lower_bound(__x), this); }
224
225 // _GLIBCXX_RESOLVE_LIB_DEFECTS
226 // 214. set::find() missing const overload
227 const_iterator
228 lower_bound(const key_type& __x) const
229 { return const_iterator(_Base::lower_bound(__x), this); }
230
231 iterator
232 upper_bound(const key_type& __x)
233 { return iterator(_Base::upper_bound(__x), this); }
234
235 // _GLIBCXX_RESOLVE_LIB_DEFECTS
236 // 214. set::find() missing const overload
237 const_iterator
238 upper_bound(const key_type& __x) const
239 { return const_iterator(_Base::upper_bound(__x), this); }
240
241 std::pair<iterator,iterator>
242 equal_range(const key_type& __x)
243 {
244 typedef typename _Base::iterator _Base_iterator;
245 std::pair<_Base_iterator, _Base_iterator> __res =
246 _Base::equal_range(__x);
247 return std::make_pair(iterator(__res.first, this),
248 iterator(__res.second, this));
249 }
250
251 // _GLIBCXX_RESOLVE_LIB_DEFECTS
252 // 214. set::find() missing const overload
253 std::pair<const_iterator,const_iterator>
254 equal_range(const key_type& __x) const
255 {
256 typedef typename _Base::const_iterator _Base_iterator;
257 std::pair<_Base_iterator, _Base_iterator> __res =
258 _Base::equal_range(__x);
259 return std::make_pair(const_iterator(__res.first, this),
260 const_iterator(__res.second, this));
261 }
262
263 _Base&
264 _M_base() { return *this; }
265
266 const _Base&
267 _M_base() const { return *this; }
268
269 private:
270 void
271 _M_invalidate_all()
272 {
273 typedef typename _Base::const_iterator _Base_const_iterator;
274 typedef __gnu_debug::_Not_equal_to<_Base_const_iterator> _Not_equal;
275 this->_M_invalidate_if(_Not_equal(_M_base().end()));
276 }
277 };
278
279 template<typename _Key, typename _Compare, typename _Allocator>
280 inline bool
281 operator==(const multiset<_Key,_Compare,_Allocator>& __lhs,
282 const multiset<_Key,_Compare,_Allocator>& __rhs)
283 { return __lhs._M_base() == __rhs._M_base(); }
284
285 template<typename _Key, typename _Compare, typename _Allocator>
286 inline bool
287 operator!=(const multiset<_Key,_Compare,_Allocator>& __lhs,
288 const multiset<_Key,_Compare,_Allocator>& __rhs)
289 { return __lhs._M_base() != __rhs._M_base(); }
290
291 template<typename _Key, typename _Compare, typename _Allocator>
292 inline bool
293 operator<(const multiset<_Key,_Compare,_Allocator>& __lhs,
294 const multiset<_Key,_Compare,_Allocator>& __rhs)
295 { return __lhs._M_base() < __rhs._M_base(); }
296
297 template<typename _Key, typename _Compare, typename _Allocator>
298 inline bool
299 operator<=(const multiset<_Key,_Compare,_Allocator>& __lhs,
300 const multiset<_Key,_Compare,_Allocator>& __rhs)
301 { return __lhs._M_base() <= __rhs._M_base(); }
302
303 template<typename _Key, typename _Compare, typename _Allocator>
304 inline bool
305 operator>=(const multiset<_Key,_Compare,_Allocator>& __lhs,
306 const multiset<_Key,_Compare,_Allocator>& __rhs)
307 { return __lhs._M_base() >= __rhs._M_base(); }
308
309 template<typename _Key, typename _Compare, typename _Allocator>
310 inline bool
311 operator>(const multiset<_Key,_Compare,_Allocator>& __lhs,
312 const multiset<_Key,_Compare,_Allocator>& __rhs)
313 { return __lhs._M_base() > __rhs._M_base(); }
314
315 template<typename _Key, typename _Compare, typename _Allocator>
316 void
317 swap(multiset<_Key,_Compare,_Allocator>& __x,
318 multiset<_Key,_Compare,_Allocator>& __y)
319 { return __x.swap(__y); }
320 } // namespace __gnu_debug_def
321 } // namespace std
322
323 #endif