Install gcc-4.4.0-tdm-1-core-2.tar.gz
[msysgit.git] / mingw / lib / gcc / mingw32 / 4.3.3 / include / c++ / debug / multimap.h
blob72f4411685b071d129052296ab26efc960e3be1c
1 // Debugging multimap implementation -*- C++ -*-
3 // Copyright (C) 2003, 2004, 2005, 2006, 2007
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.
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 // 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.
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.
31 /** @file debug/multimap.h
32 * This file is a GNU debug extension to the Standard C++ Library.
35 #ifndef _GLIBCXX_DEBUG_MULTIMAP_H
36 #define _GLIBCXX_DEBUG_MULTIMAP_H 1
38 #include <debug/safe_sequence.h>
39 #include <debug/safe_iterator.h>
40 #include <utility>
42 namespace std
44 namespace __debug
46 template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
47 typename _Allocator = std::allocator<std::pair<const _Key, _Tp> > >
48 class multimap
49 : public _GLIBCXX_STD_D::multimap<_Key, _Tp, _Compare, _Allocator>,
50 public __gnu_debug::_Safe_sequence<multimap<_Key, _Tp,
51 _Compare, _Allocator> >
53 typedef _GLIBCXX_STD_D::multimap<_Key, _Tp, _Compare, _Allocator> _Base;
54 typedef __gnu_debug::_Safe_sequence<multimap> _Safe_base;
56 public:
57 // types:
58 typedef _Key key_type;
59 typedef _Tp mapped_type;
60 typedef std::pair<const _Key, _Tp> value_type;
61 typedef _Compare key_compare;
62 typedef _Allocator allocator_type;
63 typedef typename _Base::reference reference;
64 typedef typename _Base::const_reference const_reference;
66 typedef __gnu_debug::_Safe_iterator<typename _Base::iterator, multimap>
67 iterator;
68 typedef __gnu_debug::_Safe_iterator<typename _Base::const_iterator,
69 multimap> const_iterator;
71 typedef typename _Base::size_type size_type;
72 typedef typename _Base::difference_type difference_type;
73 typedef typename _Base::pointer pointer;
74 typedef typename _Base::const_pointer const_pointer;
75 typedef std::reverse_iterator<iterator> reverse_iterator;
76 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
78 using _Base::value_compare;
80 // 23.3.1.1 construct/copy/destroy:
81 explicit multimap(const _Compare& __comp = _Compare(),
82 const _Allocator& __a = _Allocator())
83 : _Base(__comp, __a) { }
85 template<typename _InputIterator>
86 multimap(_InputIterator __first, _InputIterator __last,
87 const _Compare& __comp = _Compare(),
88 const _Allocator& __a = _Allocator())
89 : _Base(__gnu_debug::__check_valid_range(__first, __last), __last,
90 __comp, __a) { }
92 multimap(const multimap& __x)
93 : _Base(__x), _Safe_base() { }
95 multimap(const _Base& __x)
96 : _Base(__x), _Safe_base() { }
98 #ifdef __GXX_EXPERIMENTAL_CXX0X__
99 multimap(multimap&& __x)
100 : _Base(std::forward<multimap>(__x)), _Safe_base()
101 { this->_M_swap(__x); }
102 #endif
104 ~multimap() { }
106 multimap&
107 operator=(const multimap& __x)
109 *static_cast<_Base*>(this) = __x;
110 this->_M_invalidate_all();
111 return *this;
114 #ifdef __GXX_EXPERIMENTAL_CXX0X__
115 multimap&
116 operator=(multimap&& __x)
118 // NB: DR 675.
119 clear();
120 swap(__x);
121 return *this;
123 #endif
125 using _Base::get_allocator;
127 // iterators:
128 iterator
129 begin()
130 { return iterator(_Base::begin(), this); }
132 const_iterator
133 begin() const
134 { return const_iterator(_Base::begin(), this); }
136 iterator
137 end()
138 { return iterator(_Base::end(), this); }
140 const_iterator
141 end() const
142 { return const_iterator(_Base::end(), this); }
144 reverse_iterator
145 rbegin()
146 { return reverse_iterator(end()); }
148 const_reverse_iterator
149 rbegin() const
150 { return const_reverse_iterator(end()); }
152 reverse_iterator
153 rend()
154 { return reverse_iterator(begin()); }
156 const_reverse_iterator
157 rend() const
158 { return const_reverse_iterator(begin()); }
160 #ifdef __GXX_EXPERIMENTAL_CXX0X__
161 const_iterator
162 cbegin() const
163 { return const_iterator(_Base::begin(), this); }
165 const_iterator
166 cend() const
167 { return const_iterator(_Base::end(), this); }
169 const_reverse_iterator
170 crbegin() const
171 { return const_reverse_iterator(end()); }
173 const_reverse_iterator
174 crend() const
175 { return const_reverse_iterator(begin()); }
176 #endif
178 // capacity:
179 using _Base::empty;
180 using _Base::size;
181 using _Base::max_size;
183 // modifiers:
184 iterator
185 insert(const value_type& __x)
186 { return iterator(_Base::insert(__x), this); }
188 iterator
189 insert(iterator __position, const value_type& __x)
191 __glibcxx_check_insert(__position);
192 return iterator(_Base::insert(__position.base(), __x), this);
195 template<typename _InputIterator>
196 void
197 insert(_InputIterator __first, _InputIterator __last)
199 __glibcxx_check_valid_range(__first, __last);
200 _Base::insert(__first, __last);
203 void
204 erase(iterator __position)
206 __glibcxx_check_erase(__position);
207 __position._M_invalidate();
208 _Base::erase(__position.base());
211 size_type
212 erase(const key_type& __x)
214 std::pair<iterator, iterator> __victims = this->equal_range(__x);
215 size_type __count = 0;
216 while (__victims.first != __victims.second)
218 iterator __victim = __victims.first++;
219 __victim._M_invalidate();
220 _Base::erase(__victim.base());
221 ++__count;
223 return __count;
226 void
227 erase(iterator __first, iterator __last)
229 // _GLIBCXX_RESOLVE_LIB_DEFECTS
230 // 151. can't currently clear() empty container
231 __glibcxx_check_erase_range(__first, __last);
232 while (__first != __last)
233 this->erase(__first++);
236 void
237 #ifdef __GXX_EXPERIMENTAL_CXX0X__
238 swap(multimap&& __x)
239 #else
240 swap(multimap& __x)
241 #endif
243 _Base::swap(__x);
244 this->_M_swap(__x);
247 void
248 clear()
249 { this->erase(begin(), end()); }
251 // observers:
252 using _Base::key_comp;
253 using _Base::value_comp;
255 // 23.3.1.3 multimap operations:
256 iterator
257 find(const key_type& __x)
258 { return iterator(_Base::find(__x), this); }
260 const_iterator
261 find(const key_type& __x) const
262 { return const_iterator(_Base::find(__x), this); }
264 using _Base::count;
266 iterator
267 lower_bound(const key_type& __x)
268 { return iterator(_Base::lower_bound(__x), this); }
270 const_iterator
271 lower_bound(const key_type& __x) const
272 { return const_iterator(_Base::lower_bound(__x), this); }
274 iterator
275 upper_bound(const key_type& __x)
276 { return iterator(_Base::upper_bound(__x), this); }
278 const_iterator
279 upper_bound(const key_type& __x) const
280 { return const_iterator(_Base::upper_bound(__x), this); }
282 std::pair<iterator,iterator>
283 equal_range(const key_type& __x)
285 typedef typename _Base::iterator _Base_iterator;
286 std::pair<_Base_iterator, _Base_iterator> __res =
287 _Base::equal_range(__x);
288 return std::make_pair(iterator(__res.first, this),
289 iterator(__res.second, this));
292 std::pair<const_iterator,const_iterator>
293 equal_range(const key_type& __x) const
295 typedef typename _Base::const_iterator _Base_const_iterator;
296 std::pair<_Base_const_iterator, _Base_const_iterator> __res =
297 _Base::equal_range(__x);
298 return std::make_pair(const_iterator(__res.first, this),
299 const_iterator(__res.second, this));
302 _Base&
303 _M_base() { return *this; }
305 const _Base&
306 _M_base() const { return *this; }
308 private:
309 void
310 _M_invalidate_all()
312 typedef typename _Base::const_iterator _Base_const_iterator;
313 typedef __gnu_debug::_Not_equal_to<_Base_const_iterator> _Not_equal;
314 this->_M_invalidate_if(_Not_equal(_M_base().end()));
318 template<typename _Key, typename _Tp,
319 typename _Compare, typename _Allocator>
320 inline bool
321 operator==(const multimap<_Key, _Tp, _Compare, _Allocator>& __lhs,
322 const multimap<_Key, _Tp, _Compare, _Allocator>& __rhs)
323 { return __lhs._M_base() == __rhs._M_base(); }
325 template<typename _Key, typename _Tp,
326 typename _Compare, typename _Allocator>
327 inline bool
328 operator!=(const multimap<_Key, _Tp, _Compare, _Allocator>& __lhs,
329 const multimap<_Key, _Tp, _Compare, _Allocator>& __rhs)
330 { return __lhs._M_base() != __rhs._M_base(); }
332 template<typename _Key, typename _Tp,
333 typename _Compare, typename _Allocator>
334 inline bool
335 operator<(const multimap<_Key, _Tp, _Compare, _Allocator>& __lhs,
336 const multimap<_Key, _Tp, _Compare, _Allocator>& __rhs)
337 { return __lhs._M_base() < __rhs._M_base(); }
339 template<typename _Key, typename _Tp,
340 typename _Compare, typename _Allocator>
341 inline bool
342 operator<=(const multimap<_Key, _Tp, _Compare, _Allocator>& __lhs,
343 const multimap<_Key, _Tp, _Compare, _Allocator>& __rhs)
344 { return __lhs._M_base() <= __rhs._M_base(); }
346 template<typename _Key, typename _Tp,
347 typename _Compare, typename _Allocator>
348 inline bool
349 operator>=(const multimap<_Key, _Tp, _Compare, _Allocator>& __lhs,
350 const multimap<_Key, _Tp, _Compare, _Allocator>& __rhs)
351 { return __lhs._M_base() >= __rhs._M_base(); }
353 template<typename _Key, typename _Tp,
354 typename _Compare, typename _Allocator>
355 inline bool
356 operator>(const multimap<_Key, _Tp, _Compare, _Allocator>& __lhs,
357 const multimap<_Key, _Tp, _Compare, _Allocator>& __rhs)
358 { return __lhs._M_base() > __rhs._M_base(); }
360 template<typename _Key, typename _Tp,
361 typename _Compare, typename _Allocator>
362 inline void
363 swap(multimap<_Key, _Tp, _Compare, _Allocator>& __lhs,
364 multimap<_Key, _Tp, _Compare, _Allocator>& __rhs)
365 { __lhs.swap(__rhs); }
367 #ifdef __GXX_EXPERIMENTAL_CXX0X__
368 template<typename _Key, typename _Tp,
369 typename _Compare, typename _Allocator>
370 inline void
371 swap(multimap<_Key, _Tp, _Compare, _Allocator>&& __lhs,
372 multimap<_Key, _Tp, _Compare, _Allocator>& __rhs)
373 { __lhs.swap(__rhs); }
375 template<typename _Key, typename _Tp,
376 typename _Compare, typename _Allocator>
377 inline void
378 swap(multimap<_Key, _Tp, _Compare, _Allocator>& __lhs,
379 multimap<_Key, _Tp, _Compare, _Allocator>&& __rhs)
380 { __lhs.swap(__rhs); }
381 #endif
383 } // namespace __debug
384 } // namespace std
386 #endif