1 // Profiling multiset 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/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
;
46 #if __cplusplus >= 201103L
47 typedef __gnu_cxx::__alloc_traits
<_Allocator
> _Alloc_traits
;
52 typedef _Key key_type
;
53 typedef _Key value_type
;
54 typedef _Compare key_compare
;
55 typedef _Compare value_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.3.1 construct/copy/destroy:
75 explicit multiset(const _Compare
& __comp
,
76 const _Allocator
& __a
= _Allocator())
77 : _Base(__comp
, __a
) { }
79 #if __cplusplus >= 201103L
80 template<typename _InputIterator
,
81 typename
= std::_RequireInputIter
<_InputIterator
>>
83 template<typename _InputIterator
>
85 multiset(_InputIterator __first
, _InputIterator __last
,
86 const _Compare
& __comp
= _Compare(),
87 const _Allocator
& __a
= _Allocator())
88 : _Base(__first
, __last
, __comp
, __a
) { }
90 #if __cplusplus < 201103L
91 multiset(const multiset
& __x
)
94 multiset(const multiset
&) = default;
95 multiset(multiset
&&) = default;
97 multiset(initializer_list
<value_type
> __l
,
98 const _Compare
& __comp
= _Compare(),
99 const allocator_type
& __a
= allocator_type())
100 : _Base(__l
, __comp
, __a
) { }
103 multiset(const allocator_type
& __a
)
106 multiset(const multiset
& __x
, const allocator_type
& __a
)
107 : _Base(__x
, __a
) { }
109 multiset(multiset
&& __x
, const allocator_type
& __a
)
110 noexcept(is_nothrow_copy_constructible
<_Compare
>::value
111 && _Alloc_traits::_S_always_equal())
112 : _Base(std::move(__x
), __a
) { }
114 multiset(initializer_list
<value_type
> __l
, const allocator_type
& __a
)
115 : _Base(__l
, __a
) { }
117 template<typename _InputIterator
>
118 multiset(_InputIterator __first
, _InputIterator __last
,
119 const allocator_type
& __a
)
120 : _Base(__first
, __last
, __a
) { }
123 multiset(const _Base
& __x
)
126 ~multiset() _GLIBCXX_NOEXCEPT
{ }
128 #if __cplusplus < 201103L
130 operator=(const multiset
& __x
)
137 operator=(const multiset
&) = default;
140 operator=(multiset
&&) = default;
143 operator=(initializer_list
<value_type
> __l
)
150 using _Base::get_allocator
;
154 begin() _GLIBCXX_NOEXCEPT
155 { return iterator(_Base::begin()); }
158 begin() const _GLIBCXX_NOEXCEPT
159 { return const_iterator(_Base::begin()); }
162 end() _GLIBCXX_NOEXCEPT
163 { return iterator(_Base::end()); }
166 end() const _GLIBCXX_NOEXCEPT
167 { return const_iterator(_Base::end()); }
170 rbegin() _GLIBCXX_NOEXCEPT
171 { return reverse_iterator(end()); }
173 const_reverse_iterator
174 rbegin() const _GLIBCXX_NOEXCEPT
175 { return const_reverse_iterator(end()); }
178 rend() _GLIBCXX_NOEXCEPT
179 { return reverse_iterator(begin()); }
181 const_reverse_iterator
182 rend() const _GLIBCXX_NOEXCEPT
183 { return const_reverse_iterator(begin()); }
185 #if __cplusplus >= 201103L
187 cbegin() const noexcept
188 { return const_iterator(_Base::begin()); }
191 cend() const noexcept
192 { return const_iterator(_Base::end()); }
194 const_reverse_iterator
195 crbegin() const noexcept
196 { return const_reverse_iterator(end()); }
198 const_reverse_iterator
199 crend() const noexcept
200 { return const_reverse_iterator(begin()); }
206 using _Base::max_size
;
209 #if __cplusplus >= 201103L
210 template<typename
... _Args
>
212 emplace(_Args
&&... __args
)
213 { return iterator(_Base::emplace(std::forward
<_Args
>(__args
)...)); }
215 template<typename
... _Args
>
217 emplace_hint(const_iterator __pos
, _Args
&&... __args
)
219 return iterator(_Base::emplace_hint(__pos
,
220 std::forward
<_Args
>(__args
)...));
225 insert(const value_type
& __x
)
226 { return iterator(_Base::insert(__x
)); }
228 #if __cplusplus >= 201103L
230 insert(value_type
&& __x
)
231 { return iterator(_Base::insert(std::move(__x
))); }
235 insert(const_iterator __position
, const value_type
& __x
)
236 { return iterator(_Base::insert(__position
, __x
)); }
238 #if __cplusplus >= 201103L
240 insert(const_iterator __position
, value_type
&& __x
)
241 { return iterator(_Base::insert(__position
, std::move(__x
))); }
244 #if __cplusplus >= 201103L
245 template<typename _InputIterator
,
246 typename
= std::_RequireInputIter
<_InputIterator
>>
248 template<typename _InputIterator
>
251 insert(_InputIterator __first
, _InputIterator __last
)
252 { _Base::insert(__first
, __last
); }
254 #if __cplusplus >= 201103L
256 insert(initializer_list
<value_type
> __l
)
257 { _Base::insert(__l
); }
260 #if __cplusplus >= 201103L
262 erase(const_iterator __position
)
263 { return iterator(_Base::erase(__position
)); }
266 erase(iterator __position
)
267 { _Base::erase(__position
); }
271 erase(const key_type
& __x
)
273 std::pair
<iterator
, iterator
> __victims
= this->equal_range(__x
);
274 size_type __count
= 0;
275 while (__victims
.first
!= __victims
.second
)
277 iterator __victim
= __victims
.first
++;
278 _Base::erase(__victim
);
284 #if __cplusplus >= 201103L
286 erase(const_iterator __first
, const_iterator __last
)
287 { return iterator(_Base::erase(__first
, __last
)); }
290 erase(iterator __first
, iterator __last
)
291 { _Base::erase(__first
, __last
); }
296 #if __cplusplus >= 201103L
297 noexcept(_Alloc_traits::_S_nothrow_swap())
299 { _Base::swap(__x
); }
302 clear() _GLIBCXX_NOEXCEPT
303 { this->erase(begin(), end()); }
306 using _Base::key_comp
;
307 using _Base::value_comp
;
309 // multiset operations:
311 find(const key_type
& __x
)
312 { return iterator(_Base::find(__x
)); }
314 // _GLIBCXX_RESOLVE_LIB_DEFECTS
315 // 214. set::find() missing const overload
317 find(const key_type
& __x
) const
318 { return const_iterator(_Base::find(__x
)); }
323 lower_bound(const key_type
& __x
)
324 { return iterator(_Base::lower_bound(__x
)); }
326 // _GLIBCXX_RESOLVE_LIB_DEFECTS
327 // 214. set::find() missing const overload
329 lower_bound(const key_type
& __x
) const
330 { return const_iterator(_Base::lower_bound(__x
)); }
333 upper_bound(const key_type
& __x
)
334 { return iterator(_Base::upper_bound(__x
)); }
336 // _GLIBCXX_RESOLVE_LIB_DEFECTS
337 // 214. set::find() missing const overload
339 upper_bound(const key_type
& __x
) const
340 { return const_iterator(_Base::upper_bound(__x
)); }
342 std::pair
<iterator
,iterator
>
343 equal_range(const key_type
& __x
)
345 typedef typename
_Base::iterator _Base_iterator
;
346 std::pair
<_Base_iterator
, _Base_iterator
> __res
=
347 _Base::equal_range(__x
);
348 return std::make_pair(iterator(__res
.first
),
349 iterator(__res
.second
));
352 // _GLIBCXX_RESOLVE_LIB_DEFECTS
353 // 214. set::find() missing const overload
354 std::pair
<const_iterator
,const_iterator
>
355 equal_range(const key_type
& __x
) const
357 typedef typename
_Base::const_iterator _Base_iterator
;
358 std::pair
<_Base_iterator
, _Base_iterator
> __res
=
359 _Base::equal_range(__x
);
360 return std::make_pair(const_iterator(__res
.first
),
361 const_iterator(__res
.second
));
365 _M_base() _GLIBCXX_NOEXCEPT
{ return *this; }
368 _M_base() const _GLIBCXX_NOEXCEPT
{ return *this; }
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 operator<(const multiset
<_Key
, _Compare
, _Allocator
>& __lhs
,
387 const multiset
<_Key
, _Compare
, _Allocator
>& __rhs
)
388 { return __lhs
._M_base() < __rhs
._M_base(); }
390 template<typename _Key
, typename _Compare
, typename _Allocator
>
392 operator<=(const multiset
<_Key
, _Compare
, _Allocator
>& __lhs
,
393 const multiset
<_Key
, _Compare
, _Allocator
>& __rhs
)
394 { return __lhs
._M_base() <= __rhs
._M_base(); }
396 template<typename _Key
, typename _Compare
, typename _Allocator
>
398 operator>=(const multiset
<_Key
, _Compare
, _Allocator
>& __lhs
,
399 const multiset
<_Key
, _Compare
, _Allocator
>& __rhs
)
400 { return __lhs
._M_base() >= __rhs
._M_base(); }
402 template<typename _Key
, typename _Compare
, typename _Allocator
>
404 operator>(const multiset
<_Key
, _Compare
, _Allocator
>& __lhs
,
405 const multiset
<_Key
, _Compare
, _Allocator
>& __rhs
)
406 { return __lhs
._M_base() > __rhs
._M_base(); }
408 template<typename _Key
, typename _Compare
, typename _Allocator
>
410 swap(multiset
<_Key
, _Compare
, _Allocator
>& __x
,
411 multiset
<_Key
, _Compare
, _Allocator
>& __y
)
412 { return __x
.swap(__y
); }
414 } // namespace __profile