1 // Debugging multimap implementation -*- C++ -*-
3 // Copyright (C) 2003, 2004
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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
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 #ifndef _GLIBCXX_DEBUG_MULTIMAP_H
32 #define _GLIBCXX_DEBUG_MULTIMAP_H 1
34 #include <debug/safe_sequence.h>
35 #include <debug/safe_iterator.h>
38 namespace __gnu_debug_def
40 template<typename _Key
, typename _Tp
, typename _Compare
= std::less
<_Key
>,
41 typename _Allocator
= std::allocator
<std::pair
<const _Key
, _Tp
> > >
43 : public _GLIBCXX_STD::multimap
<_Key
, _Tp
, _Compare
, _Allocator
>,
44 public __gnu_debug::_Safe_sequence
<multimap
<_Key
,_Tp
,_Compare
,_Allocator
> >
46 typedef _GLIBCXX_STD::multimap
<_Key
, _Tp
, _Compare
, _Allocator
> _Base
;
47 typedef __gnu_debug::_Safe_sequence
<multimap
> _Safe_base
;
51 typedef _Key key_type
;
52 typedef _Tp mapped_type
;
53 typedef std::pair
<const _Key
, _Tp
> value_type
;
54 typedef _Compare key_compare
;
55 typedef _Allocator allocator_type
;
56 typedef typename
_Allocator::reference reference
;
57 typedef typename
_Allocator::const_reference const_reference
;
59 typedef __gnu_debug::_Safe_iterator
<typename
_Base::iterator
, multimap
>
61 typedef __gnu_debug::_Safe_iterator
<typename
_Base::const_iterator
,
62 multimap
> const_iterator
;
64 typedef typename
_Base::size_type size_type
;
65 typedef typename
_Base::difference_type difference_type
;
66 typedef typename
_Allocator::pointer pointer
;
67 typedef typename
_Allocator::const_pointer const_pointer
;
68 typedef std::reverse_iterator
<iterator
> reverse_iterator
;
69 typedef std::reverse_iterator
<const_iterator
> const_reverse_iterator
;
71 using _Base::value_compare
;
73 // 23.3.1.1 construct/copy/destroy:
74 explicit multimap(const _Compare
& __comp
= _Compare(),
75 const _Allocator
& __a
= _Allocator())
76 : _Base(__comp
, __a
) { }
78 template<typename _InputIterator
>
79 multimap(_InputIterator __first
, _InputIterator __last
,
80 const _Compare
& __comp
= _Compare(),
81 const _Allocator
& __a
= _Allocator())
82 : _Base(__gnu_debug::__check_valid_range(__first
, __last
), __last
,
85 multimap(const multimap
<_Key
,_Tp
,_Compare
,_Allocator
>& __x
)
86 : _Base(__x
), _Safe_base() { }
88 multimap(const _Base
& __x
) : _Base(__x
), _Safe_base() { }
92 multimap
<_Key
,_Tp
,_Compare
,_Allocator
>&
93 operator=(const multimap
<_Key
,_Tp
,_Compare
,_Allocator
>& __x
)
95 *static_cast<_Base
*>(this) = __x
;
96 this->_M_invalidate_all();
100 using _Base::get_allocator
;
105 { return iterator(_Base::begin(), this); }
109 { return const_iterator(_Base::begin(), this); }
113 { return iterator(_Base::end(), this); }
117 { return const_iterator(_Base::end(), this); }
121 { return reverse_iterator(end()); }
123 const_reverse_iterator
125 { return const_reverse_iterator(end()); }
129 { return reverse_iterator(begin()); }
131 const_reverse_iterator
133 { return const_reverse_iterator(begin()); }
138 using _Base::max_size
;
142 insert(const value_type
& __x
)
143 { return iterator(_Base::insert(__x
), this); }
146 insert(iterator __position
, const value_type
& __x
)
148 __glibcxx_check_insert(__position
);
149 return iterator(_Base::insert(__position
.base(), __x
), this);
152 template<typename _InputIterator
>
154 insert(_InputIterator __first
, _InputIterator __last
)
156 __glibcxx_check_valid_range(__first
, __last
);
157 _Base::insert(__first
, __last
);
161 erase(iterator __position
)
163 __glibcxx_check_erase(__position
);
164 __position
._M_invalidate();
165 _Base::erase(__position
.base());
169 erase(const key_type
& __x
)
171 std::pair
<iterator
, iterator
> __victims
= this->equal_range(__x
);
172 size_type __count
= 0;
173 while (__victims
.first
!= __victims
.second
)
175 iterator __victim
= __victims
.first
++;
176 __victim
._M_invalidate();
177 _Base::erase(__victim
.base());
184 erase(iterator __first
, iterator __last
)
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
++);
194 swap(multimap
<_Key
,_Tp
,_Compare
,_Allocator
>& __x
)
202 { this->erase(begin(), end()); }
205 using _Base::key_comp
;
206 using _Base::value_comp
;
208 // 23.3.1.3 multimap operations:
210 find(const key_type
& __x
)
211 { return iterator(_Base::find(__x
), this); }
214 find(const key_type
& __x
) const
215 { return const_iterator(_Base::find(__x
), this); }
220 lower_bound(const key_type
& __x
)
221 { return iterator(_Base::lower_bound(__x
), this); }
224 lower_bound(const key_type
& __x
) const
225 { return const_iterator(_Base::lower_bound(__x
), this); }
228 upper_bound(const key_type
& __x
)
229 { return iterator(_Base::upper_bound(__x
), this); }
232 upper_bound(const key_type
& __x
) const
233 { return const_iterator(_Base::upper_bound(__x
), this); }
235 std::pair
<iterator
,iterator
>
236 equal_range(const key_type
& __x
)
238 typedef typename
_Base::iterator _Base_iterator
;
239 std::pair
<_Base_iterator
, _Base_iterator
> __res
=
240 _Base::equal_range(__x
);
241 return std::make_pair(iterator(__res
.first
, this),
242 iterator(__res
.second
, this));
245 std::pair
<const_iterator
,const_iterator
>
246 equal_range(const key_type
& __x
) const
248 typedef typename
_Base::const_iterator _Base_const_iterator
;
249 std::pair
<_Base_const_iterator
, _Base_const_iterator
> __res
=
250 _Base::equal_range(__x
);
251 return std::make_pair(const_iterator(__res
.first
, this),
252 const_iterator(__res
.second
, this));
256 _M_base() { return *this; }
259 _M_base() const { return *this; }
265 typedef typename
_Base::const_iterator _Base_const_iterator
;
266 typedef __gnu_debug::_Not_equal_to
<_Base_const_iterator
> _Not_equal
;
267 this->_M_invalidate_if(_Not_equal(_M_base().end()));
271 template<typename _Key
,typename _Tp
,typename _Compare
,typename _Allocator
>
273 operator==(const multimap
<_Key
,_Tp
,_Compare
,_Allocator
>& __lhs
,
274 const multimap
<_Key
,_Tp
,_Compare
,_Allocator
>& __rhs
)
275 { return __lhs
._M_base() == __rhs
._M_base(); }
277 template<typename _Key
,typename _Tp
,typename _Compare
,typename _Allocator
>
279 operator!=(const multimap
<_Key
,_Tp
,_Compare
,_Allocator
>& __lhs
,
280 const multimap
<_Key
,_Tp
,_Compare
,_Allocator
>& __rhs
)
281 { return __lhs
._M_base() != __rhs
._M_base(); }
283 template<typename _Key
,typename _Tp
,typename _Compare
,typename _Allocator
>
285 operator<(const multimap
<_Key
,_Tp
,_Compare
,_Allocator
>& __lhs
,
286 const multimap
<_Key
,_Tp
,_Compare
,_Allocator
>& __rhs
)
287 { return __lhs
._M_base() < __rhs
._M_base(); }
289 template<typename _Key
,typename _Tp
,typename _Compare
,typename _Allocator
>
291 operator<=(const multimap
<_Key
,_Tp
,_Compare
,_Allocator
>& __lhs
,
292 const multimap
<_Key
,_Tp
,_Compare
,_Allocator
>& __rhs
)
293 { return __lhs
._M_base() <= __rhs
._M_base(); }
295 template<typename _Key
,typename _Tp
,typename _Compare
,typename _Allocator
>
297 operator>=(const multimap
<_Key
,_Tp
,_Compare
,_Allocator
>& __lhs
,
298 const multimap
<_Key
,_Tp
,_Compare
,_Allocator
>& __rhs
)
299 { return __lhs
._M_base() >= __rhs
._M_base(); }
301 template<typename _Key
,typename _Tp
,typename _Compare
,typename _Allocator
>
303 operator>(const multimap
<_Key
,_Tp
,_Compare
,_Allocator
>& __lhs
,
304 const multimap
<_Key
,_Tp
,_Compare
,_Allocator
>& __rhs
)
305 { return __lhs
._M_base() > __rhs
._M_base(); }
307 template<typename _Key
,typename _Tp
,typename _Compare
,typename _Allocator
>
309 swap(multimap
<_Key
,_Tp
,_Compare
,_Allocator
>& __lhs
,
310 multimap
<_Key
,_Tp
,_Compare
,_Allocator
>& __rhs
)
311 { __lhs
.swap(__rhs
); }
312 } // namespace __gnu_debug_def