Remove outermost loop parameter.
[official-gcc/graphite-test-results.git] / libstdc++-v3 / include / debug / multiset.h
blob9f65ba34b282011a082d59934d401e0b97377530
1 // Debugging multiset implementation -*- C++ -*-
3 // Copyright (C) 2003, 2004, 2005, 2006, 2007, 2009, 2010
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 3, or (at your option)
10 // any later version.
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.
17 // Under Section 7 of GPL version 3, you are granted additional
18 // permissions described in the GCC Runtime Library Exception, version
19 // 3.1, as published by the Free Software Foundation.
21 // You should have received a copy of the GNU General Public License and
22 // a copy of the GCC Runtime Library Exception along with this program;
23 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 // <http://www.gnu.org/licenses/>.
26 /** @file debug/multiset.h
27 * This file is a GNU debug extension to the Standard C++ Library.
30 #ifndef _GLIBCXX_DEBUG_MULTISET_H
31 #define _GLIBCXX_DEBUG_MULTISET_H 1
33 #include <debug/safe_sequence.h>
34 #include <debug/safe_iterator.h>
35 #include <utility>
37 namespace std
39 namespace __debug
41 /// Class std::multiset with safety/checking/debug instrumentation.
42 template<typename _Key, typename _Compare = std::less<_Key>,
43 typename _Allocator = std::allocator<_Key> >
44 class multiset
45 : public _GLIBCXX_STD_D::multiset<_Key, _Compare, _Allocator>,
46 public __gnu_debug::_Safe_sequence<multiset<_Key, _Compare, _Allocator> >
48 typedef _GLIBCXX_STD_D::multiset<_Key, _Compare, _Allocator> _Base;
49 typedef __gnu_debug::_Safe_sequence<multiset> _Safe_base;
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;
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;
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;
73 // 23.3.3.1 construct/copy/destroy:
74 explicit multiset(const _Compare& __comp = _Compare(),
75 const _Allocator& __a = _Allocator())
76 : _Base(__comp, __a) { }
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) { }
85 multiset(const multiset& __x)
86 : _Base(__x), _Safe_base() { }
88 multiset(const _Base& __x)
89 : _Base(__x), _Safe_base() { }
91 #ifdef __GXX_EXPERIMENTAL_CXX0X__
92 multiset(multiset&& __x)
93 : _Base(std::forward<multiset>(__x)), _Safe_base()
94 { this->_M_swap(__x); }
96 multiset(initializer_list<value_type> __l,
97 const _Compare& __comp = _Compare(),
98 const allocator_type& __a = allocator_type())
99 : _Base(__l, __comp, __a), _Safe_base() { }
100 #endif
102 ~multiset() { }
104 multiset&
105 operator=(const multiset& __x)
107 *static_cast<_Base*>(this) = __x;
108 this->_M_invalidate_all();
109 return *this;
112 #ifdef __GXX_EXPERIMENTAL_CXX0X__
113 multiset&
114 operator=(multiset&& __x)
116 // NB: DR 1204.
117 // NB: DR 675.
118 clear();
119 swap(__x);
120 return *this;
123 multiset&
124 operator=(initializer_list<value_type> __l)
126 this->clear();
127 this->insert(__l);
128 return *this;
130 #endif
132 using _Base::get_allocator;
134 // iterators:
135 iterator
136 begin()
137 { return iterator(_Base::begin(), this); }
139 const_iterator
140 begin() const
141 { return const_iterator(_Base::begin(), this); }
143 iterator
144 end()
145 { return iterator(_Base::end(), this); }
147 const_iterator
148 end() const
149 { return const_iterator(_Base::end(), this); }
151 reverse_iterator
152 rbegin()
153 { return reverse_iterator(end()); }
155 const_reverse_iterator
156 rbegin() const
157 { return const_reverse_iterator(end()); }
159 reverse_iterator
160 rend()
161 { return reverse_iterator(begin()); }
163 const_reverse_iterator
164 rend() const
165 { return const_reverse_iterator(begin()); }
167 #ifdef __GXX_EXPERIMENTAL_CXX0X__
168 const_iterator
169 cbegin() const
170 { return const_iterator(_Base::begin(), this); }
172 const_iterator
173 cend() const
174 { return const_iterator(_Base::end(), this); }
176 const_reverse_iterator
177 crbegin() const
178 { return const_reverse_iterator(end()); }
180 const_reverse_iterator
181 crend() const
182 { return const_reverse_iterator(begin()); }
183 #endif
185 // capacity:
186 using _Base::empty;
187 using _Base::size;
188 using _Base::max_size;
190 // modifiers:
191 iterator
192 insert(const value_type& __x)
193 { return iterator(_Base::insert(__x), this); }
195 iterator
196 insert(iterator __position, const value_type& __x)
198 __glibcxx_check_insert(__position);
199 return iterator(_Base::insert(__position.base(), __x), this);
202 template<typename _InputIterator>
203 void
204 insert(_InputIterator __first, _InputIterator __last)
206 __glibcxx_check_valid_range(__first, __last);
207 _Base::insert(__first, __last);
210 #ifdef __GXX_EXPERIMENTAL_CXX0X__
211 void
212 insert(initializer_list<value_type> __l)
213 { _Base::insert(__l); }
214 #endif
216 #ifdef __GXX_EXPERIMENTAL_CXX0X__
217 iterator
218 erase(iterator __position)
220 __glibcxx_check_erase(__position);
221 __position._M_invalidate();
222 return iterator(_Base::erase(__position.base()), this);
224 #else
225 void
226 erase(iterator __position)
228 __glibcxx_check_erase(__position);
229 __position._M_invalidate();
230 _Base::erase(__position.base());
232 #endif
234 size_type
235 erase(const key_type& __x)
237 std::pair<iterator, iterator> __victims = this->equal_range(__x);
238 size_type __count = 0;
239 while (__victims.first != __victims.second)
241 iterator __victim = __victims.first++;
242 __victim._M_invalidate();
243 _Base::erase(__victim.base());
244 ++__count;
246 return __count;
249 #ifdef __GXX_EXPERIMENTAL_CXX0X__
250 iterator
251 erase(iterator __first, iterator __last)
253 // _GLIBCXX_RESOLVE_LIB_DEFECTS
254 // 151. can't currently clear() empty container
255 __glibcxx_check_erase_range(__first, __last);
256 while (__first != __last)
257 this->erase(__first++);
258 return __last;
260 #else
261 void
262 erase(iterator __first, iterator __last)
264 // _GLIBCXX_RESOLVE_LIB_DEFECTS
265 // 151. can't currently clear() empty container
266 __glibcxx_check_erase_range(__first, __last);
267 while (__first != __last)
268 this->erase(__first++);
270 #endif
272 void
273 swap(multiset& __x)
275 _Base::swap(__x);
276 this->_M_swap(__x);
279 void
280 clear()
281 { this->erase(begin(), end()); }
283 // observers:
284 using _Base::key_comp;
285 using _Base::value_comp;
287 // multiset operations:
288 iterator
289 find(const key_type& __x)
290 { return iterator(_Base::find(__x), this); }
292 // _GLIBCXX_RESOLVE_LIB_DEFECTS
293 // 214. set::find() missing const overload
294 const_iterator
295 find(const key_type& __x) const
296 { return const_iterator(_Base::find(__x), this); }
298 using _Base::count;
300 iterator
301 lower_bound(const key_type& __x)
302 { return iterator(_Base::lower_bound(__x), this); }
304 // _GLIBCXX_RESOLVE_LIB_DEFECTS
305 // 214. set::find() missing const overload
306 const_iterator
307 lower_bound(const key_type& __x) const
308 { return const_iterator(_Base::lower_bound(__x), this); }
310 iterator
311 upper_bound(const key_type& __x)
312 { return iterator(_Base::upper_bound(__x), this); }
314 // _GLIBCXX_RESOLVE_LIB_DEFECTS
315 // 214. set::find() missing const overload
316 const_iterator
317 upper_bound(const key_type& __x) const
318 { return const_iterator(_Base::upper_bound(__x), this); }
320 std::pair<iterator,iterator>
321 equal_range(const key_type& __x)
323 typedef typename _Base::iterator _Base_iterator;
324 std::pair<_Base_iterator, _Base_iterator> __res =
325 _Base::equal_range(__x);
326 return std::make_pair(iterator(__res.first, this),
327 iterator(__res.second, this));
330 // _GLIBCXX_RESOLVE_LIB_DEFECTS
331 // 214. set::find() missing const overload
332 std::pair<const_iterator,const_iterator>
333 equal_range(const key_type& __x) const
335 typedef typename _Base::const_iterator _Base_iterator;
336 std::pair<_Base_iterator, _Base_iterator> __res =
337 _Base::equal_range(__x);
338 return std::make_pair(const_iterator(__res.first, this),
339 const_iterator(__res.second, this));
342 _Base&
343 _M_base() { return *this; }
345 const _Base&
346 _M_base() const { return *this; }
348 private:
349 void
350 _M_invalidate_all()
352 typedef typename _Base::const_iterator _Base_const_iterator;
353 typedef __gnu_debug::_Not_equal_to<_Base_const_iterator> _Not_equal;
354 this->_M_invalidate_if(_Not_equal(_M_base().end()));
358 template<typename _Key, typename _Compare, typename _Allocator>
359 inline bool
360 operator==(const multiset<_Key, _Compare, _Allocator>& __lhs,
361 const multiset<_Key, _Compare, _Allocator>& __rhs)
362 { return __lhs._M_base() == __rhs._M_base(); }
364 template<typename _Key, typename _Compare, typename _Allocator>
365 inline bool
366 operator!=(const multiset<_Key, _Compare, _Allocator>& __lhs,
367 const multiset<_Key, _Compare, _Allocator>& __rhs)
368 { return __lhs._M_base() != __rhs._M_base(); }
370 template<typename _Key, typename _Compare, typename _Allocator>
371 inline bool
372 operator<(const multiset<_Key, _Compare, _Allocator>& __lhs,
373 const multiset<_Key, _Compare, _Allocator>& __rhs)
374 { return __lhs._M_base() < __rhs._M_base(); }
376 template<typename _Key, typename _Compare, typename _Allocator>
377 inline bool
378 operator<=(const multiset<_Key, _Compare, _Allocator>& __lhs,
379 const multiset<_Key, _Compare, _Allocator>& __rhs)
380 { return __lhs._M_base() <= __rhs._M_base(); }
382 template<typename _Key, typename _Compare, typename _Allocator>
383 inline bool
384 operator>=(const multiset<_Key, _Compare, _Allocator>& __lhs,
385 const multiset<_Key, _Compare, _Allocator>& __rhs)
386 { return __lhs._M_base() >= __rhs._M_base(); }
388 template<typename _Key, typename _Compare, typename _Allocator>
389 inline bool
390 operator>(const multiset<_Key, _Compare, _Allocator>& __lhs,
391 const multiset<_Key, _Compare, _Allocator>& __rhs)
392 { return __lhs._M_base() > __rhs._M_base(); }
394 template<typename _Key, typename _Compare, typename _Allocator>
395 void
396 swap(multiset<_Key, _Compare, _Allocator>& __x,
397 multiset<_Key, _Compare, _Allocator>& __y)
398 { return __x.swap(__y); }
400 } // namespace __debug
401 } // namespace std
403 #endif