1 // Profiling multiset implementation -*- C++ -*-
3 // Copyright (C) 2009-2012 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/multiset.h
26 * This file is a GNU profile extension to the Standard C++ Library.
29 #ifndef _GLIBCXX_PROFILE_MULTISET_H
30 #define _GLIBCXX_PROFILE_MULTISET_H 1
34 namespace std
_GLIBCXX_VISIBILITY(default)
38 /// Class std::multiset wrapper with performance instrumentation.
39 template<typename _Key
, typename _Compare
= std::less
<_Key
>,
40 typename _Allocator
= std::allocator
<_Key
> >
42 : public _GLIBCXX_STD_C::multiset
<_Key
, _Compare
, _Allocator
>
44 typedef _GLIBCXX_STD_C::multiset
<_Key
, _Compare
, _Allocator
> _Base
;
48 typedef _Key key_type
;
49 typedef _Key value_type
;
50 typedef _Compare key_compare
;
51 typedef _Compare value_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 // 23.3.3.1 construct/copy/destroy:
67 explicit multiset(const _Compare
& __comp
= _Compare(),
68 const _Allocator
& __a
= _Allocator())
69 : _Base(__comp
, __a
) { }
71 #if __cplusplus >= 201103L
72 template<typename _InputIterator
,
73 typename
= std::_RequireInputIter
<_InputIterator
>>
75 template<typename _InputIterator
>
77 multiset(_InputIterator __first
, _InputIterator __last
,
78 const _Compare
& __comp
= _Compare(),
79 const _Allocator
& __a
= _Allocator())
80 : _Base(__first
, __last
, __comp
, __a
) { }
82 multiset(const multiset
& __x
)
85 multiset(const _Base
& __x
)
88 #if __cplusplus >= 201103L
89 multiset(multiset
&& __x
)
90 noexcept(is_nothrow_copy_constructible
<_Compare
>::value
)
91 : _Base(std::move(__x
))
94 multiset(initializer_list
<value_type
> __l
,
95 const _Compare
& __comp
= _Compare(),
96 const allocator_type
& __a
= allocator_type())
97 : _Base(__l
, __comp
, __a
) { }
100 ~multiset() _GLIBCXX_NOEXCEPT
{ }
103 operator=(const multiset
& __x
)
105 *static_cast<_Base
*>(this) = __x
;
109 #if __cplusplus >= 201103L
111 operator=(multiset
&& __x
)
121 operator=(initializer_list
<value_type
> __l
)
129 using _Base::get_allocator
;
133 begin() _GLIBCXX_NOEXCEPT
134 { return iterator(_Base::begin()); }
137 begin() const _GLIBCXX_NOEXCEPT
138 { return const_iterator(_Base::begin()); }
141 end() _GLIBCXX_NOEXCEPT
142 { return iterator(_Base::end()); }
145 end() const _GLIBCXX_NOEXCEPT
146 { return const_iterator(_Base::end()); }
149 rbegin() _GLIBCXX_NOEXCEPT
150 { return reverse_iterator(end()); }
152 const_reverse_iterator
153 rbegin() const _GLIBCXX_NOEXCEPT
154 { return const_reverse_iterator(end()); }
157 rend() _GLIBCXX_NOEXCEPT
158 { return reverse_iterator(begin()); }
160 const_reverse_iterator
161 rend() const _GLIBCXX_NOEXCEPT
162 { return const_reverse_iterator(begin()); }
164 #if __cplusplus >= 201103L
166 cbegin() const noexcept
167 { return const_iterator(_Base::begin()); }
170 cend() const noexcept
171 { return const_iterator(_Base::end()); }
173 const_reverse_iterator
174 crbegin() const noexcept
175 { return const_reverse_iterator(end()); }
177 const_reverse_iterator
178 crend() const noexcept
179 { return const_reverse_iterator(begin()); }
185 using _Base::max_size
;
188 #if __cplusplus >= 201103L
189 template<typename
... _Args
>
191 emplace(_Args
&&... __args
)
192 { return iterator(_Base::emplace(std::forward
<_Args
>(__args
)...)); }
194 template<typename
... _Args
>
196 emplace_hint(const_iterator __pos
, _Args
&&... __args
)
198 return iterator(_Base::emplace_hint(__pos
,
199 std::forward
<_Args
>(__args
)...));
204 insert(const value_type
& __x
)
205 { return iterator(_Base::insert(__x
)); }
207 #if __cplusplus >= 201103L
209 insert(value_type
&& __x
)
210 { return iterator(_Base::insert(std::move(__x
))); }
214 insert(const_iterator __position
, const value_type
& __x
)
215 { return iterator(_Base::insert(__position
, __x
)); }
217 #if __cplusplus >= 201103L
219 insert(const_iterator __position
, value_type
&& __x
)
220 { return iterator(_Base::insert(__position
, std::move(__x
))); }
223 #if __cplusplus >= 201103L
224 template<typename _InputIterator
,
225 typename
= std::_RequireInputIter
<_InputIterator
>>
227 template<typename _InputIterator
>
230 insert(_InputIterator __first
, _InputIterator __last
)
231 { _Base::insert(__first
, __last
); }
233 #if __cplusplus >= 201103L
235 insert(initializer_list
<value_type
> __l
)
236 { _Base::insert(__l
); }
239 #if __cplusplus >= 201103L
241 erase(const_iterator __position
)
242 { return iterator(_Base::erase(__position
)); }
245 erase(iterator __position
)
246 { _Base::erase(__position
); }
250 erase(const key_type
& __x
)
252 std::pair
<iterator
, iterator
> __victims
= this->equal_range(__x
);
253 size_type __count
= 0;
254 while (__victims
.first
!= __victims
.second
)
256 iterator __victim
= __victims
.first
++;
257 _Base::erase(__victim
);
263 #if __cplusplus >= 201103L
265 erase(const_iterator __first
, const_iterator __last
)
266 { return iterator(_Base::erase(__first
, __last
)); }
269 erase(iterator __first
, iterator __last
)
270 { _Base::erase(__first
, __last
); }
275 { _Base::swap(__x
); }
278 clear() _GLIBCXX_NOEXCEPT
279 { this->erase(begin(), end()); }
282 using _Base::key_comp
;
283 using _Base::value_comp
;
285 // multiset operations:
287 find(const key_type
& __x
)
288 { return iterator(_Base::find(__x
)); }
290 // _GLIBCXX_RESOLVE_LIB_DEFECTS
291 // 214. set::find() missing const overload
293 find(const key_type
& __x
) const
294 { return const_iterator(_Base::find(__x
)); }
299 lower_bound(const key_type
& __x
)
300 { return iterator(_Base::lower_bound(__x
)); }
302 // _GLIBCXX_RESOLVE_LIB_DEFECTS
303 // 214. set::find() missing const overload
305 lower_bound(const key_type
& __x
) const
306 { return const_iterator(_Base::lower_bound(__x
)); }
309 upper_bound(const key_type
& __x
)
310 { return iterator(_Base::upper_bound(__x
)); }
312 // _GLIBCXX_RESOLVE_LIB_DEFECTS
313 // 214. set::find() missing const overload
315 upper_bound(const key_type
& __x
) const
316 { return const_iterator(_Base::upper_bound(__x
)); }
318 std::pair
<iterator
,iterator
>
319 equal_range(const key_type
& __x
)
321 typedef typename
_Base::iterator _Base_iterator
;
322 std::pair
<_Base_iterator
, _Base_iterator
> __res
=
323 _Base::equal_range(__x
);
324 return std::make_pair(iterator(__res
.first
),
325 iterator(__res
.second
));
328 // _GLIBCXX_RESOLVE_LIB_DEFECTS
329 // 214. set::find() missing const overload
330 std::pair
<const_iterator
,const_iterator
>
331 equal_range(const key_type
& __x
) const
333 typedef typename
_Base::const_iterator _Base_iterator
;
334 std::pair
<_Base_iterator
, _Base_iterator
> __res
=
335 _Base::equal_range(__x
);
336 return std::make_pair(const_iterator(__res
.first
),
337 const_iterator(__res
.second
));
341 _M_base() _GLIBCXX_NOEXCEPT
{ return *this; }
344 _M_base() const _GLIBCXX_NOEXCEPT
{ return *this; }
348 template<typename _Key
, typename _Compare
, typename _Allocator
>
350 operator==(const multiset
<_Key
, _Compare
, _Allocator
>& __lhs
,
351 const multiset
<_Key
, _Compare
, _Allocator
>& __rhs
)
352 { return __lhs
._M_base() == __rhs
._M_base(); }
354 template<typename _Key
, typename _Compare
, typename _Allocator
>
356 operator!=(const multiset
<_Key
, _Compare
, _Allocator
>& __lhs
,
357 const multiset
<_Key
, _Compare
, _Allocator
>& __rhs
)
358 { return __lhs
._M_base() != __rhs
._M_base(); }
360 template<typename _Key
, typename _Compare
, typename _Allocator
>
362 operator<(const multiset
<_Key
, _Compare
, _Allocator
>& __lhs
,
363 const multiset
<_Key
, _Compare
, _Allocator
>& __rhs
)
364 { return __lhs
._M_base() < __rhs
._M_base(); }
366 template<typename _Key
, typename _Compare
, typename _Allocator
>
368 operator<=(const multiset
<_Key
, _Compare
, _Allocator
>& __lhs
,
369 const multiset
<_Key
, _Compare
, _Allocator
>& __rhs
)
370 { return __lhs
._M_base() <= __rhs
._M_base(); }
372 template<typename _Key
, typename _Compare
, typename _Allocator
>
374 operator>=(const multiset
<_Key
, _Compare
, _Allocator
>& __lhs
,
375 const multiset
<_Key
, _Compare
, _Allocator
>& __rhs
)
376 { return __lhs
._M_base() >= __rhs
._M_base(); }
378 template<typename _Key
, typename _Compare
, typename _Allocator
>
380 operator>(const multiset
<_Key
, _Compare
, _Allocator
>& __lhs
,
381 const multiset
<_Key
, _Compare
, _Allocator
>& __rhs
)
382 { return __lhs
._M_base() > __rhs
._M_base(); }
384 template<typename _Key
, typename _Compare
, typename _Allocator
>
386 swap(multiset
<_Key
, _Compare
, _Allocator
>& __x
,
387 multiset
<_Key
, _Compare
, _Allocator
>& __y
)
388 { return __x
.swap(__y
); }
390 } // namespace __profile