1 // Profiling multimap implementation -*- C++ -*-
3 // Copyright (C) 2009-2014 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
34 namespace std
_GLIBCXX_VISIBILITY(default)
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_C::multimap
<_Key
, _Tp
, _Compare
, _Allocator
>
44 typedef _GLIBCXX_STD_C::multimap
<_Key
, _Tp
, _Compare
, _Allocator
> _Base
;
46 #if __cplusplus >= 201103L
47 typedef __gnu_cxx::__alloc_traits
<_Allocator
> _Alloc_traits
;
52 typedef _Key key_type
;
53 typedef _Tp mapped_type
;
54 typedef std::pair
<const _Key
, _Tp
> value_type
;
55 typedef _Compare key_compare
;
56 typedef _Allocator allocator_type
;
57 typedef typename
_Base::reference reference
;
58 typedef typename
_Base::const_reference const_reference
;
60 typedef typename
_Base::iterator iterator
;
61 typedef typename
_Base::const_iterator const_iterator
;
62 typedef typename
_Base::reverse_iterator reverse_iterator
;
63 typedef typename
_Base::const_reverse_iterator const_reverse_iterator
;
65 typedef typename
_Base::size_type size_type
;
66 typedef typename
_Base::difference_type difference_type
;
67 typedef typename
_Base::pointer pointer
;
68 typedef typename
_Base::const_pointer const_pointer
;
70 // 23.3.1.1 construct/copy/destroy:
71 explicit multimap(const _Compare
& __comp
= _Compare(),
72 const _Allocator
& __a
= _Allocator())
73 : _Base(__comp
, __a
) { }
75 #if __cplusplus >= 201103L
76 template<typename _InputIterator
,
77 typename
= std::_RequireInputIter
<_InputIterator
>>
79 template<typename _InputIterator
>
81 multimap(_InputIterator __first
, _InputIterator __last
,
82 const _Compare
& __comp
= _Compare(),
83 const _Allocator
& __a
= _Allocator())
84 : _Base(__first
, __last
, __comp
, __a
) { }
86 #if __cplusplus < 201103L
87 multimap(const multimap
& __x
)
90 multimap(const multimap
&) = default;
91 multimap(multimap
&&) = default;
93 multimap(initializer_list
<value_type
> __l
,
94 const _Compare
& __c
= _Compare(),
95 const allocator_type
& __a
= allocator_type())
96 : _Base(__l
, __c
, __a
) { }
99 multimap(const allocator_type
& __a
)
102 multimap(const multimap
& __x
, const allocator_type
& __a
)
103 : _Base(__x
, __a
) { }
105 multimap(multimap
&& __x
, const allocator_type
& __a
)
106 noexcept(is_nothrow_copy_constructible
<_Compare
>::value
107 && _Alloc_traits::_S_always_equal())
108 : _Base(std::move(__x
), __a
) { }
110 multimap(initializer_list
<value_type
> __l
, const allocator_type
& __a
)
111 : _Base(__l
, __a
) { }
113 template<typename _InputIterator
>
114 multimap(_InputIterator __first
, _InputIterator __last
,
115 const allocator_type
& __a
)
116 : _Base(__first
, __last
, __a
) { }
119 multimap(const _Base
& __x
)
122 ~multimap() _GLIBCXX_NOEXCEPT
{ }
124 #if __cplusplus < 201103L
126 operator=(const multimap
& __x
)
133 operator=(const multimap
&) = default;
136 operator=(multimap
&&) = default;
139 operator=(initializer_list
<value_type
> __l
)
146 using _Base::get_allocator
;
150 begin() _GLIBCXX_NOEXCEPT
151 { return iterator(_Base::begin()); }
154 begin() const _GLIBCXX_NOEXCEPT
155 { return const_iterator(_Base::begin()); }
158 end() _GLIBCXX_NOEXCEPT
159 { return iterator(_Base::end()); }
162 end() const _GLIBCXX_NOEXCEPT
163 { return const_iterator(_Base::end()); }
166 rbegin() _GLIBCXX_NOEXCEPT
167 { return reverse_iterator(end()); }
169 const_reverse_iterator
170 rbegin() const _GLIBCXX_NOEXCEPT
171 { return const_reverse_iterator(end()); }
174 rend() _GLIBCXX_NOEXCEPT
175 { return reverse_iterator(begin()); }
177 const_reverse_iterator
178 rend() const _GLIBCXX_NOEXCEPT
179 { return const_reverse_iterator(begin()); }
181 #if __cplusplus >= 201103L
183 cbegin() const noexcept
184 { return const_iterator(_Base::begin()); }
187 cend() const noexcept
188 { return const_iterator(_Base::end()); }
190 const_reverse_iterator
191 crbegin() const noexcept
192 { return const_reverse_iterator(end()); }
194 const_reverse_iterator
195 crend() const noexcept
196 { return const_reverse_iterator(begin()); }
202 using _Base::max_size
;
205 #if __cplusplus >= 201103L
206 template<typename
... _Args
>
208 emplace(_Args
&&... __args
)
210 return iterator(_Base::emplace(std::forward
<_Args
>(__args
)...));
213 template<typename
... _Args
>
215 emplace_hint(const_iterator __pos
, _Args
&&... __args
)
217 return iterator(_Base::emplace_hint(__pos
,
218 std::forward
<_Args
>(__args
)...));
223 insert(const value_type
& __x
)
224 { return iterator(_Base::insert(__x
)); }
226 #if __cplusplus >= 201103L
227 template<typename _Pair
, typename
= typename
228 std::enable_if
<std::is_constructible
<value_type
,
229 _Pair
&&>::value
>::type
>
232 { return iterator(_Base::insert(std::forward
<_Pair
>(__x
))); }
235 #if __cplusplus >= 201103L
237 insert(std::initializer_list
<value_type
> __list
)
238 { _Base::insert(__list
); }
242 #if __cplusplus >= 201103L
243 insert(const_iterator __position
, const value_type
& __x
)
245 insert(iterator __position
, const value_type
& __x
)
247 { return iterator(_Base::insert(__position
, __x
)); }
249 #if __cplusplus >= 201103L
250 template<typename _Pair
, typename
= typename
251 std::enable_if
<std::is_constructible
<value_type
,
252 _Pair
&&>::value
>::type
>
254 insert(const_iterator __position
, _Pair
&& __x
)
255 { return iterator(_Base::insert(__position
,
256 std::forward
<_Pair
>(__x
))); }
259 #if __cplusplus >= 201103L
260 template<typename _InputIterator
,
261 typename
= std::_RequireInputIter
<_InputIterator
>>
263 template<typename _InputIterator
>
266 insert(_InputIterator __first
, _InputIterator __last
)
267 { _Base::insert(__first
, __last
); }
269 #if __cplusplus >= 201103L
271 erase(const_iterator __position
)
272 { return iterator(_Base::erase(__position
)); }
275 erase(iterator __position
)
276 { return iterator(_Base::erase(__position
)); }
279 erase(iterator __position
)
280 { _Base::erase(__position
); }
284 erase(const key_type
& __x
)
286 std::pair
<iterator
, iterator
> __victims
= this->equal_range(__x
);
287 size_type __count
= 0;
288 while (__victims
.first
!= __victims
.second
)
290 iterator __victim
= __victims
.first
++;
291 _Base::erase(__victim
);
297 #if __cplusplus >= 201103L
299 erase(const_iterator __first
, const_iterator __last
)
300 { return iterator(_Base::erase(__first
, __last
)); }
303 erase(iterator __first
, iterator __last
)
304 { _Base::erase(__first
, __last
); }
309 #if __cplusplus >= 201103L
310 noexcept(_Alloc_traits::_S_nothrow_swap())
312 { _Base::swap(__x
); }
315 clear() _GLIBCXX_NOEXCEPT
316 { this->erase(begin(), end()); }
319 using _Base::key_comp
;
320 using _Base::value_comp
;
322 // 23.3.1.3 multimap operations:
324 find(const key_type
& __x
)
325 { return iterator(_Base::find(__x
)); }
328 find(const key_type
& __x
) const
329 { return const_iterator(_Base::find(__x
)); }
334 lower_bound(const key_type
& __x
)
335 { return iterator(_Base::lower_bound(__x
)); }
338 lower_bound(const key_type
& __x
) const
339 { return const_iterator(_Base::lower_bound(__x
)); }
342 upper_bound(const key_type
& __x
)
343 { return iterator(_Base::upper_bound(__x
)); }
346 upper_bound(const key_type
& __x
) const
347 { return const_iterator(_Base::upper_bound(__x
)); }
349 std::pair
<iterator
,iterator
>
350 equal_range(const key_type
& __x
)
352 typedef typename
_Base::iterator _Base_iterator
;
353 std::pair
<_Base_iterator
, _Base_iterator
> __res
=
354 _Base::equal_range(__x
);
355 return std::make_pair(iterator(__res
.first
),
356 iterator(__res
.second
));
359 std::pair
<const_iterator
,const_iterator
>
360 equal_range(const key_type
& __x
) const
362 typedef typename
_Base::const_iterator _Base_const_iterator
;
363 std::pair
<_Base_const_iterator
, _Base_const_iterator
> __res
=
364 _Base::equal_range(__x
);
365 return std::make_pair(const_iterator(__res
.first
),
366 const_iterator(__res
.second
));
370 _M_base() _GLIBCXX_NOEXCEPT
{ return *this; }
373 _M_base() const _GLIBCXX_NOEXCEPT
{ return *this; }
376 template<typename _Key
, typename _Tp
,
377 typename _Compare
, typename _Allocator
>
379 operator==(const multimap
<_Key
, _Tp
, _Compare
, _Allocator
>& __lhs
,
380 const multimap
<_Key
, _Tp
, _Compare
, _Allocator
>& __rhs
)
381 { return __lhs
._M_base() == __rhs
._M_base(); }
383 template<typename _Key
, typename _Tp
,
384 typename _Compare
, typename _Allocator
>
386 operator!=(const multimap
<_Key
, _Tp
, _Compare
, _Allocator
>& __lhs
,
387 const multimap
<_Key
, _Tp
, _Compare
, _Allocator
>& __rhs
)
388 { return __lhs
._M_base() != __rhs
._M_base(); }
390 template<typename _Key
, typename _Tp
,
391 typename _Compare
, typename _Allocator
>
393 operator<(const multimap
<_Key
, _Tp
, _Compare
, _Allocator
>& __lhs
,
394 const multimap
<_Key
, _Tp
, _Compare
, _Allocator
>& __rhs
)
395 { return __lhs
._M_base() < __rhs
._M_base(); }
397 template<typename _Key
, typename _Tp
,
398 typename _Compare
, typename _Allocator
>
400 operator<=(const multimap
<_Key
, _Tp
, _Compare
, _Allocator
>& __lhs
,
401 const multimap
<_Key
, _Tp
, _Compare
, _Allocator
>& __rhs
)
402 { return __lhs
._M_base() <= __rhs
._M_base(); }
404 template<typename _Key
, typename _Tp
,
405 typename _Compare
, typename _Allocator
>
407 operator>=(const multimap
<_Key
, _Tp
, _Compare
, _Allocator
>& __lhs
,
408 const multimap
<_Key
, _Tp
, _Compare
, _Allocator
>& __rhs
)
409 { return __lhs
._M_base() >= __rhs
._M_base(); }
411 template<typename _Key
, typename _Tp
,
412 typename _Compare
, typename _Allocator
>
414 operator>(const multimap
<_Key
, _Tp
, _Compare
, _Allocator
>& __lhs
,
415 const multimap
<_Key
, _Tp
, _Compare
, _Allocator
>& __rhs
)
416 { return __lhs
._M_base() > __rhs
._M_base(); }
418 template<typename _Key
, typename _Tp
,
419 typename _Compare
, typename _Allocator
>
421 swap(multimap
<_Key
, _Tp
, _Compare
, _Allocator
>& __lhs
,
422 multimap
<_Key
, _Tp
, _Compare
, _Allocator
>& __rhs
)
423 { __lhs
.swap(__rhs
); }
425 } // namespace __profile