1 // Profiling multimap implementation -*- C++ -*-
3 // Copyright (C) 2009, 2010 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
25 /** @file profile/multimap.h
26 * This file is a GNU profile extension to the Standard C++ Library.
29 #ifndef _GLIBCXX_PROFILE_MULTIMAP_H
30 #define _GLIBCXX_PROFILE_MULTIMAP_H 1
38 /// Class std::multimap wrapper with performance instrumentation.
39 template<typename _Key
, typename _Tp
, typename _Compare
= std::less
<_Key
>,
40 typename _Allocator
= std::allocator
<std::pair
<const _Key
, _Tp
> > >
42 : public _GLIBCXX_STD_D::multimap
<_Key
, _Tp
, _Compare
, _Allocator
>
44 typedef _GLIBCXX_STD_D::multimap
<_Key
, _Tp
, _Compare
, _Allocator
> _Base
;
48 typedef _Key key_type
;
49 typedef _Tp mapped_type
;
50 typedef std::pair
<const _Key
, _Tp
> value_type
;
51 typedef _Compare key_compare
;
52 typedef _Allocator allocator_type
;
53 typedef typename
_Base::reference reference
;
54 typedef typename
_Base::const_reference const_reference
;
56 typedef typename
_Base::iterator iterator
;
57 typedef typename
_Base::const_iterator const_iterator
;
58 typedef typename
_Base::reverse_iterator reverse_iterator
;
59 typedef typename
_Base::const_reverse_iterator const_reverse_iterator
;
61 typedef typename
_Base::size_type size_type
;
62 typedef typename
_Base::difference_type difference_type
;
63 typedef typename
_Base::pointer pointer
;
64 typedef typename
_Base::const_pointer const_pointer
;
66 using _Base::value_compare
;
68 // 23.3.1.1 construct/copy/destroy:
69 explicit multimap(const _Compare
& __comp
= _Compare(),
70 const _Allocator
& __a
= _Allocator())
71 : _Base(__comp
, __a
) { }
73 template<typename _InputIterator
>
74 multimap(_InputIterator __first
, _InputIterator __last
,
75 const _Compare
& __comp
= _Compare(),
76 const _Allocator
& __a
= _Allocator())
77 : _Base(__first
, __last
, __comp
, __a
) { }
79 multimap(const multimap
& __x
)
82 multimap(const _Base
& __x
)
85 #ifdef __GXX_EXPERIMENTAL_CXX0X__
86 multimap(multimap
&& __x
)
87 : _Base(std::move(__x
))
90 multimap(initializer_list
<value_type
> __l
,
91 const _Compare
& __c
= _Compare(),
92 const allocator_type
& __a
= allocator_type())
93 : _Base(__l
, __c
, __a
) { }
99 operator=(const multimap
& __x
)
101 *static_cast<_Base
*>(this) = __x
;
105 #ifdef __GXX_EXPERIMENTAL_CXX0X__
107 operator=(multimap
&& __x
)
117 operator=(initializer_list
<value_type
> __l
)
125 using _Base::get_allocator
;
130 { return iterator(_Base::begin()); }
134 { return const_iterator(_Base::begin()); }
138 { return iterator(_Base::end()); }
142 { return const_iterator(_Base::end()); }
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()); }
167 { return const_iterator(_Base::end()); }
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
)); }
188 #ifdef __GXX_EXPERIMENTAL_CXX0X__
190 insert(std::initializer_list
<value_type
> __list
)
191 { _Base::insert(__list
); }
195 #ifdef __GXX_EXPERIMENTAL_CXX0X__
196 insert(const_iterator __position
, const value_type
& __x
)
198 insert(iterator __position
, const value_type
& __x
)
200 { return iterator(_Base::insert(__position
, __x
)); }
202 template<typename _InputIterator
>
204 insert(_InputIterator __first
, _InputIterator __last
)
205 { _Base::insert(__first
, __last
); }
207 #ifdef __GXX_EXPERIMENTAL_CXX0X__
209 erase(const_iterator __position
)
210 { return iterator(_Base::erase(__position
)); }
213 erase(iterator __position
)
214 { _Base::erase(__position
); }
218 erase(const key_type
& __x
)
220 std::pair
<iterator
, iterator
> __victims
= this->equal_range(__x
);
221 size_type __count
= 0;
222 while (__victims
.first
!= __victims
.second
)
224 iterator __victim
= __victims
.first
++;
225 _Base::erase(__victim
);
231 #ifdef __GXX_EXPERIMENTAL_CXX0X__
233 erase(const_iterator __first
, const_iterator __last
)
234 { return iterator(_Base::erase(__first
, __last
)); }
237 erase(iterator __first
, iterator __last
)
238 { _Base::erase(__first
, __last
); }
243 { _Base::swap(__x
); }
247 { this->erase(begin(), end()); }
250 using _Base::key_comp
;
251 using _Base::value_comp
;
253 // 23.3.1.3 multimap operations:
255 find(const key_type
& __x
)
256 { return iterator(_Base::find(__x
)); }
259 find(const key_type
& __x
) const
260 { return const_iterator(_Base::find(__x
)); }
265 lower_bound(const key_type
& __x
)
266 { return iterator(_Base::lower_bound(__x
)); }
269 lower_bound(const key_type
& __x
) const
270 { return const_iterator(_Base::lower_bound(__x
)); }
273 upper_bound(const key_type
& __x
)
274 { return iterator(_Base::upper_bound(__x
)); }
277 upper_bound(const key_type
& __x
) const
278 { return const_iterator(_Base::upper_bound(__x
)); }
280 std::pair
<iterator
,iterator
>
281 equal_range(const key_type
& __x
)
283 typedef typename
_Base::iterator _Base_iterator
;
284 std::pair
<_Base_iterator
, _Base_iterator
> __res
=
285 _Base::equal_range(__x
);
286 return std::make_pair(iterator(__res
.first
),
287 iterator(__res
.second
));
290 std::pair
<const_iterator
,const_iterator
>
291 equal_range(const key_type
& __x
) const
293 typedef typename
_Base::const_iterator _Base_const_iterator
;
294 std::pair
<_Base_const_iterator
, _Base_const_iterator
> __res
=
295 _Base::equal_range(__x
);
296 return std::make_pair(const_iterator(__res
.first
),
297 const_iterator(__res
.second
));
301 _M_base() { return *this; }
304 _M_base() const { return *this; }
307 template<typename _Key
, typename _Tp
,
308 typename _Compare
, typename _Allocator
>
310 operator==(const multimap
<_Key
, _Tp
, _Compare
, _Allocator
>& __lhs
,
311 const multimap
<_Key
, _Tp
, _Compare
, _Allocator
>& __rhs
)
312 { return __lhs
._M_base() == __rhs
._M_base(); }
314 template<typename _Key
, typename _Tp
,
315 typename _Compare
, typename _Allocator
>
317 operator!=(const multimap
<_Key
, _Tp
, _Compare
, _Allocator
>& __lhs
,
318 const multimap
<_Key
, _Tp
, _Compare
, _Allocator
>& __rhs
)
319 { return __lhs
._M_base() != __rhs
._M_base(); }
321 template<typename _Key
, typename _Tp
,
322 typename _Compare
, typename _Allocator
>
324 operator<(const multimap
<_Key
, _Tp
, _Compare
, _Allocator
>& __lhs
,
325 const multimap
<_Key
, _Tp
, _Compare
, _Allocator
>& __rhs
)
326 { return __lhs
._M_base() < __rhs
._M_base(); }
328 template<typename _Key
, typename _Tp
,
329 typename _Compare
, typename _Allocator
>
331 operator<=(const multimap
<_Key
, _Tp
, _Compare
, _Allocator
>& __lhs
,
332 const multimap
<_Key
, _Tp
, _Compare
, _Allocator
>& __rhs
)
333 { return __lhs
._M_base() <= __rhs
._M_base(); }
335 template<typename _Key
, typename _Tp
,
336 typename _Compare
, typename _Allocator
>
338 operator>=(const multimap
<_Key
, _Tp
, _Compare
, _Allocator
>& __lhs
,
339 const multimap
<_Key
, _Tp
, _Compare
, _Allocator
>& __rhs
)
340 { return __lhs
._M_base() >= __rhs
._M_base(); }
342 template<typename _Key
, typename _Tp
,
343 typename _Compare
, typename _Allocator
>
345 operator>(const multimap
<_Key
, _Tp
, _Compare
, _Allocator
>& __lhs
,
346 const multimap
<_Key
, _Tp
, _Compare
, _Allocator
>& __rhs
)
347 { return __lhs
._M_base() > __rhs
._M_base(); }
349 template<typename _Key
, typename _Tp
,
350 typename _Compare
, typename _Allocator
>
352 swap(multimap
<_Key
, _Tp
, _Compare
, _Allocator
>& __lhs
,
353 multimap
<_Key
, _Tp
, _Compare
, _Allocator
>& __rhs
)
354 { __lhs
.swap(__rhs
); }
356 } // namespace __profile