1 // Debugging multimap implementation -*- C++ -*-
3 // Copyright (C) 2003, 2004, 2005, 2006, 2007
4 // Free Software Foundation, Inc.
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)
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,
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>
46 template<typename _Key
, typename _Tp
, typename _Compare
= std::less
<_Key
>,
47 typename _Allocator
= std::allocator
<std::pair
<const _Key
, _Tp
> > >
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
;
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
>
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
,
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
); }
107 operator=(const multimap
& __x
)
109 *static_cast<_Base
*>(this) = __x
;
110 this->_M_invalidate_all();
114 #ifdef __GXX_EXPERIMENTAL_CXX0X__
116 operator=(multimap
&& __x
)
125 using _Base::get_allocator
;
130 { return iterator(_Base::begin(), this); }
134 { return const_iterator(_Base::begin(), this); }
138 { return iterator(_Base::end(), this); }
142 { return const_iterator(_Base::end(), this); }
146 { return reverse_iterator(end()); }
148 const_reverse_iterator
150 { return const_reverse_iterator(end()); }
154 { return reverse_iterator(begin()); }
156 const_reverse_iterator
158 { return const_reverse_iterator(begin()); }
160 #ifdef __GXX_EXPERIMENTAL_CXX0X__
163 { return const_iterator(_Base::begin(), this); }
167 { return const_iterator(_Base::end(), this); }
169 const_reverse_iterator
171 { return const_reverse_iterator(end()); }
173 const_reverse_iterator
175 { return const_reverse_iterator(begin()); }
181 using _Base::max_size
;
185 insert(const value_type
& __x
)
186 { return iterator(_Base::insert(__x
), this); }
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
>
197 insert(_InputIterator __first
, _InputIterator __last
)
199 __glibcxx_check_valid_range(__first
, __last
);
200 _Base::insert(__first
, __last
);
204 erase(iterator __position
)
206 __glibcxx_check_erase(__position
);
207 __position
._M_invalidate();
208 _Base::erase(__position
.base());
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());
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
++);
237 #ifdef __GXX_EXPERIMENTAL_CXX0X__
249 { this->erase(begin(), end()); }
252 using _Base::key_comp
;
253 using _Base::value_comp
;
255 // 23.3.1.3 multimap operations:
257 find(const key_type
& __x
)
258 { return iterator(_Base::find(__x
), this); }
261 find(const key_type
& __x
) const
262 { return const_iterator(_Base::find(__x
), this); }
267 lower_bound(const key_type
& __x
)
268 { return iterator(_Base::lower_bound(__x
), this); }
271 lower_bound(const key_type
& __x
) const
272 { return const_iterator(_Base::lower_bound(__x
), this); }
275 upper_bound(const key_type
& __x
)
276 { return iterator(_Base::upper_bound(__x
), this); }
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));
303 _M_base() { return *this; }
306 _M_base() const { return *this; }
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
>
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
>
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
>
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
>
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
>
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
>
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
>
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
>
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
>
378 swap(multimap
<_Key
, _Tp
, _Compare
, _Allocator
>& __lhs
,
379 multimap
<_Key
, _Tp
, _Compare
, _Allocator
>&& __rhs
)
380 { __lhs
.swap(__rhs
); }
383 } // namespace __debug