]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/include/debug/multiset.h
re PR libstdc++/58764 ([lwg/2193] error: converting to ‘const std::vector<std::basic_...
[thirdparty/gcc.git] / libstdc++-v3 / include / debug / multiset.h
CommitLineData
285b36d6
BK
1// Debugging multiset implementation -*- C++ -*-
2
aa118a03 3// Copyright (C) 2003-2014 Free Software Foundation, Inc.
285b36d6
BK
4//
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
748086b7 8// Free Software Foundation; either version 3, or (at your option)
285b36d6
BK
9// any later version.
10
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.
15
748086b7
JJ
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.
19
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/>.
285b36d6 24
78a53887
BK
25/** @file debug/multiset.h
26 * This file is a GNU debug extension to the Standard C++ Library.
27 */
28
285b36d6
BK
29#ifndef _GLIBCXX_DEBUG_MULTISET_H
30#define _GLIBCXX_DEBUG_MULTISET_H 1
31
32#include <debug/safe_sequence.h>
33#include <debug/safe_iterator.h>
34#include <utility>
35
12ffa228 36namespace std _GLIBCXX_VISIBILITY(default)
3cbc7af0 37{
45f388bb 38namespace __debug
285b36d6 39{
1ceb9e06 40 /// Class std::multiset with safety/checking/debug instrumentation.
285b36d6
BK
41 template<typename _Key, typename _Compare = std::less<_Key>,
42 typename _Allocator = std::allocator<_Key> >
526da49c 43 class multiset
12ffa228 44 : public _GLIBCXX_STD_C::multiset<_Key, _Compare, _Allocator>,
285b36d6
BK
45 public __gnu_debug::_Safe_sequence<multiset<_Key, _Compare, _Allocator> >
46 {
12ffa228 47 typedef _GLIBCXX_STD_C::multiset<_Key, _Compare, _Allocator> _Base;
285b36d6 48
afe96d41
FD
49 typedef typename _Base::const_iterator _Base_const_iterator;
50 typedef typename _Base::iterator _Base_iterator;
51 typedef __gnu_debug::_Equal_to<_Base_const_iterator> _Equal;
51835a80
FD
52
53#if __cplusplus >= 201103L
54 typedef __gnu_cxx::__alloc_traits<typename
55 _Base::allocator_type> _Alloc_traits;
56#endif
285b36d6
BK
57 public:
58 // types:
526da49c
BI
59 typedef _Key key_type;
60 typedef _Key value_type;
61 typedef _Compare key_compare;
62 typedef _Compare value_compare;
63 typedef _Allocator allocator_type;
09952acc
PC
64 typedef typename _Base::reference reference;
65 typedef typename _Base::const_reference const_reference;
285b36d6 66
afe96d41 67 typedef __gnu_debug::_Safe_iterator<_Base_iterator, multiset>
285b36d6 68 iterator;
afe96d41 69 typedef __gnu_debug::_Safe_iterator<_Base_const_iterator,
285b36d6
BK
70 multiset> const_iterator;
71
72 typedef typename _Base::size_type size_type;
73 typedef typename _Base::difference_type difference_type;
09952acc
PC
74 typedef typename _Base::pointer pointer;
75 typedef typename _Base::const_pointer const_pointer;
285b36d6
BK
76 typedef std::reverse_iterator<iterator> reverse_iterator;
77 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
78
79 // 23.3.3.1 construct/copy/destroy:
c3cdd71f
JW
80
81 multiset() : _Base() { }
82
83 explicit multiset(const _Compare& __comp,
285b36d6
BK
84 const _Allocator& __a = _Allocator())
85 : _Base(__comp, __a) { }
86
87 template<typename _InputIterator>
88 multiset(_InputIterator __first, _InputIterator __last,
89 const _Compare& __comp = _Compare(),
90 const _Allocator& __a = _Allocator())
1f5ca1a1
PC
91 : _Base(__gnu_debug::__base(__gnu_debug::__check_valid_range(__first,
92 __last)),
93 __gnu_debug::__base(__last),
285b36d6
BK
94 __comp, __a) { }
95
ed540c0a 96 multiset(const multiset& __x)
4c2d93db 97 : _Base(__x) { }
526da49c 98
ed540c0a 99 multiset(const _Base& __x)
4c2d93db 100 : _Base(__x) { }
ed540c0a 101
734f5023 102#if __cplusplus >= 201103L
ed540c0a 103 multiset(multiset&& __x)
6f59ea25 104 noexcept(is_nothrow_copy_constructible<_Compare>::value)
4c2d93db 105 : _Base(std::move(__x))
ed540c0a 106 { this->_M_swap(__x); }
988499f4
JM
107
108 multiset(initializer_list<value_type> __l,
109 const _Compare& __comp = _Compare(),
110 const allocator_type& __a = allocator_type())
4c2d93db 111 : _Base(__l, __comp, __a) { }
51835a80
FD
112
113 explicit
114 multiset(const allocator_type& __a)
115 : _Base(__a) { }
116
117 multiset(const multiset& __m, const allocator_type& __a)
118 : _Base(__m, __a) { }
119
120 multiset(multiset&& __m, const allocator_type& __a)
121 : _Base(std::move(__m._M_base()), __a) { }
122
123 multiset(initializer_list<value_type> __l, const allocator_type& __a)
124 : _Base(__l, __a)
125 { }
126
127 template<typename _InputIterator>
128 multiset(_InputIterator __first, _InputIterator __last,
129 const allocator_type& __a)
130 : _Base(__gnu_debug::__base(__gnu_debug::__check_valid_range(__first,
131 __last)),
132 __gnu_debug::__base(__last), __a)
133 { }
ed540c0a 134#endif
285b36d6 135
6f59ea25 136 ~multiset() _GLIBCXX_NOEXCEPT { }
285b36d6 137
ed540c0a
CJ
138 multiset&
139 operator=(const multiset& __x)
285b36d6 140 {
51835a80 141 _M_base() = __x;
285b36d6
BK
142 this->_M_invalidate_all();
143 return *this;
144 }
145
734f5023 146#if __cplusplus >= 201103L
ed540c0a
CJ
147 multiset&
148 operator=(multiset&& __x)
51835a80 149 noexcept(_Alloc_traits::_S_nothrow_move())
ed540c0a 150 {
739fd6a6 151 __glibcxx_check_self_move_assign(__x);
51835a80
FD
152 bool xfer_memory = _Alloc_traits::_S_propagate_on_move_assign()
153 || __x.get_allocator() == this->get_allocator();
154 _M_base() = std::move(__x._M_base());
155 if (xfer_memory)
156 this->_M_swap(__x);
157 else
158 this->_M_invalidate_all();
159 __x._M_invalidate_all();
ed540c0a
CJ
160 return *this;
161 }
988499f4
JM
162
163 multiset&
164 operator=(initializer_list<value_type> __l)
165 {
51835a80
FD
166 _M_base() = __l;
167 this->_M_invalidate_all();
988499f4
JM
168 return *this;
169 }
ed540c0a
CJ
170#endif
171
285b36d6
BK
172 using _Base::get_allocator;
173
174 // iterators:
175 iterator
d3677132 176 begin() _GLIBCXX_NOEXCEPT
285b36d6
BK
177 { return iterator(_Base::begin(), this); }
178
526da49c 179 const_iterator
d3677132 180 begin() const _GLIBCXX_NOEXCEPT
285b36d6
BK
181 { return const_iterator(_Base::begin(), this); }
182
526da49c 183 iterator
d3677132 184 end() _GLIBCXX_NOEXCEPT
285b36d6
BK
185 { return iterator(_Base::end(), this); }
186
526da49c 187 const_iterator
d3677132 188 end() const _GLIBCXX_NOEXCEPT
285b36d6
BK
189 { return const_iterator(_Base::end(), this); }
190
526da49c 191 reverse_iterator
d3677132 192 rbegin() _GLIBCXX_NOEXCEPT
285b36d6
BK
193 { return reverse_iterator(end()); }
194
526da49c 195 const_reverse_iterator
d3677132 196 rbegin() const _GLIBCXX_NOEXCEPT
285b36d6
BK
197 { return const_reverse_iterator(end()); }
198
526da49c 199 reverse_iterator
d3677132 200 rend() _GLIBCXX_NOEXCEPT
285b36d6
BK
201 { return reverse_iterator(begin()); }
202
526da49c 203 const_reverse_iterator
d3677132 204 rend() const _GLIBCXX_NOEXCEPT
285b36d6
BK
205 { return const_reverse_iterator(begin()); }
206
734f5023 207#if __cplusplus >= 201103L
0cd50f89 208 const_iterator
d3677132 209 cbegin() const noexcept
0cd50f89
PC
210 { return const_iterator(_Base::begin(), this); }
211
212 const_iterator
d3677132 213 cend() const noexcept
0cd50f89
PC
214 { return const_iterator(_Base::end(), this); }
215
216 const_reverse_iterator
d3677132 217 crbegin() const noexcept
0cd50f89
PC
218 { return const_reverse_iterator(end()); }
219
220 const_reverse_iterator
d3677132 221 crend() const noexcept
0cd50f89
PC
222 { return const_reverse_iterator(begin()); }
223#endif
224
285b36d6
BK
225 // capacity:
226 using _Base::empty;
227 using _Base::size;
228 using _Base::max_size;
229
230 // modifiers:
734f5023 231#if __cplusplus >= 201103L
55826ab6
FD
232 template<typename... _Args>
233 iterator
234 emplace(_Args&&... __args)
235 {
236 return iterator(_Base::emplace(std::forward<_Args>(__args)...), this);
237 }
238
239 template<typename... _Args>
240 iterator
241 emplace_hint(const_iterator __pos, _Args&&... __args)
242 {
243 __glibcxx_check_insert(__pos);
244 return iterator(_Base::emplace_hint(__pos.base(),
245 std::forward<_Args>(__args)...),
246 this);
247 }
248#endif
249
526da49c 250 iterator
285b36d6
BK
251 insert(const value_type& __x)
252 { return iterator(_Base::insert(__x), this); }
253
734f5023 254#if __cplusplus >= 201103L
e6a05448
PC
255 iterator
256 insert(value_type&& __x)
257 { return iterator(_Base::insert(std::move(__x)), this); }
258#endif
259
526da49c 260 iterator
6b6d5d09 261 insert(const_iterator __position, const value_type& __x)
285b36d6
BK
262 {
263 __glibcxx_check_insert(__position);
264 return iterator(_Base::insert(__position.base(), __x), this);
265 }
266
734f5023 267#if __cplusplus >= 201103L
e6a05448
PC
268 iterator
269 insert(const_iterator __position, value_type&& __x)
270 {
271 __glibcxx_check_insert(__position);
272 return iterator(_Base::insert(__position.base(), std::move(__x)),
273 this);
274 }
275#endif
276
285b36d6 277 template<typename _InputIterator>
1f5ca1a1
PC
278 void
279 insert(_InputIterator __first, _InputIterator __last)
280 {
281 __glibcxx_check_valid_range(__first, __last);
282 _Base::insert(__gnu_debug::__base(__first),
283 __gnu_debug::__base(__last));
284 }
285b36d6 285
734f5023 286#if __cplusplus >= 201103L
988499f4
JM
287 void
288 insert(initializer_list<value_type> __l)
289 { _Base::insert(__l); }
290#endif
291
734f5023 292#if __cplusplus >= 201103L
5ab06c6d 293 iterator
6b6d5d09 294 erase(const_iterator __position)
5ab06c6d
PC
295 {
296 __glibcxx_check_erase(__position);
afe96d41 297 this->_M_invalidate_if(_Equal(__position.base()));
5ab06c6d
PC
298 return iterator(_Base::erase(__position.base()), this);
299 }
300#else
526da49c 301 void
285b36d6
BK
302 erase(iterator __position)
303 {
304 __glibcxx_check_erase(__position);
afe96d41 305 this->_M_invalidate_if(_Equal(__position.base()));
285b36d6
BK
306 _Base::erase(__position.base());
307 }
5ab06c6d 308#endif
285b36d6
BK
309
310 size_type
311 erase(const key_type& __x)
312 {
afe96d41
FD
313 std::pair<_Base_iterator, _Base_iterator> __victims =
314 _Base::equal_range(__x);
285b36d6 315 size_type __count = 0;
afe96d41
FD
316 _Base_iterator __victim = __victims.first;
317 while (__victim != __victims.second)
318 {
319 this->_M_invalidate_if(_Equal(__victim));
320 _Base::erase(__victim++);
321 ++__count;
322 }
285b36d6
BK
323 return __count;
324 }
325
734f5023 326#if __cplusplus >= 201103L
5ab06c6d 327 iterator
6b6d5d09 328 erase(const_iterator __first, const_iterator __last)
5ab06c6d
PC
329 {
330 // _GLIBCXX_RESOLVE_LIB_DEFECTS
331 // 151. can't currently clear() empty container
332 __glibcxx_check_erase_range(__first, __last);
afe96d41
FD
333 for (_Base_const_iterator __victim = __first.base();
334 __victim != __last.base(); ++__victim)
335 {
336 _GLIBCXX_DEBUG_VERIFY(__victim != _Base::end(),
337 _M_message(__gnu_debug::__msg_valid_range)
338 ._M_iterator(__first, "first")
339 ._M_iterator(__last, "last"));
340 this->_M_invalidate_if(_Equal(__victim));
341 }
342 return iterator(_Base::erase(__first.base(), __last.base()), this);
5ab06c6d
PC
343 }
344#else
526da49c 345 void
285b36d6
BK
346 erase(iterator __first, iterator __last)
347 {
348 // _GLIBCXX_RESOLVE_LIB_DEFECTS
349 // 151. can't currently clear() empty container
350 __glibcxx_check_erase_range(__first, __last);
afe96d41
FD
351 for (_Base_iterator __victim = __first.base();
352 __victim != __last.base(); ++__victim)
353 {
354 _GLIBCXX_DEBUG_VERIFY(__victim != _Base::end(),
355 _M_message(__gnu_debug::__msg_valid_range)
356 ._M_iterator(__first, "first")
357 ._M_iterator(__last, "last"));
358 this->_M_invalidate_if(_Equal(__victim));
359 }
360 _Base::erase(__first.base(), __last.base());
285b36d6 361 }
5ab06c6d 362#endif
285b36d6 363
526da49c 364 void
ed540c0a 365 swap(multiset& __x)
51835a80
FD
366#if __cplusplus >= 201103L
367 noexcept(_Alloc_traits::_S_nothrow_swap())
368#endif
285b36d6 369 {
51835a80
FD
370#if __cplusplus >= 201103L
371 if (!_Alloc_traits::_S_propagate_on_swap())
372 __glibcxx_check_equal_allocs(__x);
373#endif
285b36d6
BK
374 _Base::swap(__x);
375 this->_M_swap(__x);
376 }
377
526da49c 378 void
d3677132 379 clear() _GLIBCXX_NOEXCEPT
afe96d41
FD
380 {
381 this->_M_invalidate_all();
382 _Base::clear();
383 }
285b36d6
BK
384
385 // observers:
386 using _Base::key_comp;
387 using _Base::value_comp;
388
389 // multiset operations:
526da49c 390 iterator
285b36d6
BK
391 find(const key_type& __x)
392 { return iterator(_Base::find(__x), this); }
393
394 // _GLIBCXX_RESOLVE_LIB_DEFECTS
395 // 214. set::find() missing const overload
526da49c 396 const_iterator
285b36d6
BK
397 find(const key_type& __x) const
398 { return const_iterator(_Base::find(__x), this); }
399
400 using _Base::count;
401
526da49c 402 iterator
285b36d6
BK
403 lower_bound(const key_type& __x)
404 { return iterator(_Base::lower_bound(__x), this); }
405
406 // _GLIBCXX_RESOLVE_LIB_DEFECTS
407 // 214. set::find() missing const overload
526da49c 408 const_iterator
285b36d6
BK
409 lower_bound(const key_type& __x) const
410 { return const_iterator(_Base::lower_bound(__x), this); }
411
526da49c 412 iterator
285b36d6
BK
413 upper_bound(const key_type& __x)
414 { return iterator(_Base::upper_bound(__x), this); }
415
416 // _GLIBCXX_RESOLVE_LIB_DEFECTS
417 // 214. set::find() missing const overload
526da49c 418 const_iterator
285b36d6
BK
419 upper_bound(const key_type& __x) const
420 { return const_iterator(_Base::upper_bound(__x), this); }
421
422 std::pair<iterator,iterator>
423 equal_range(const key_type& __x)
424 {
285b36d6 425 std::pair<_Base_iterator, _Base_iterator> __res =
afe96d41 426 _Base::equal_range(__x);
285b36d6
BK
427 return std::make_pair(iterator(__res.first, this),
428 iterator(__res.second, this));
429 }
430
431 // _GLIBCXX_RESOLVE_LIB_DEFECTS
432 // 214. set::find() missing const overload
433 std::pair<const_iterator,const_iterator>
434 equal_range(const key_type& __x) const
435 {
afe96d41
FD
436 std::pair<_Base_const_iterator, _Base_const_iterator> __res =
437 _Base::equal_range(__x);
285b36d6
BK
438 return std::make_pair(const_iterator(__res.first, this),
439 const_iterator(__res.second, this));
440 }
441
526da49c 442 _Base&
d3677132 443 _M_base() _GLIBCXX_NOEXCEPT { return *this; }
285b36d6 444
526da49c 445 const _Base&
d3677132 446 _M_base() const _GLIBCXX_NOEXCEPT { return *this; }
526da49c 447
285b36d6 448 private:
526da49c 449 void
285b36d6
BK
450 _M_invalidate_all()
451 {
285b36d6 452 typedef __gnu_debug::_Not_equal_to<_Base_const_iterator> _Not_equal;
afe96d41 453 this->_M_invalidate_if(_Not_equal(_Base::end()));
285b36d6
BK
454 }
455 };
456
457 template<typename _Key, typename _Compare, typename _Allocator>
526da49c 458 inline bool
ed540c0a
CJ
459 operator==(const multiset<_Key, _Compare, _Allocator>& __lhs,
460 const multiset<_Key, _Compare, _Allocator>& __rhs)
285b36d6
BK
461 { return __lhs._M_base() == __rhs._M_base(); }
462
463 template<typename _Key, typename _Compare, typename _Allocator>
526da49c 464 inline bool
ed540c0a
CJ
465 operator!=(const multiset<_Key, _Compare, _Allocator>& __lhs,
466 const multiset<_Key, _Compare, _Allocator>& __rhs)
285b36d6
BK
467 { return __lhs._M_base() != __rhs._M_base(); }
468
469 template<typename _Key, typename _Compare, typename _Allocator>
526da49c 470 inline bool
ed540c0a
CJ
471 operator<(const multiset<_Key, _Compare, _Allocator>& __lhs,
472 const multiset<_Key, _Compare, _Allocator>& __rhs)
285b36d6
BK
473 { return __lhs._M_base() < __rhs._M_base(); }
474
475 template<typename _Key, typename _Compare, typename _Allocator>
526da49c 476 inline bool
ed540c0a
CJ
477 operator<=(const multiset<_Key, _Compare, _Allocator>& __lhs,
478 const multiset<_Key, _Compare, _Allocator>& __rhs)
285b36d6
BK
479 { return __lhs._M_base() <= __rhs._M_base(); }
480
481 template<typename _Key, typename _Compare, typename _Allocator>
526da49c 482 inline bool
ed540c0a
CJ
483 operator>=(const multiset<_Key, _Compare, _Allocator>& __lhs,
484 const multiset<_Key, _Compare, _Allocator>& __rhs)
285b36d6
BK
485 { return __lhs._M_base() >= __rhs._M_base(); }
486
487 template<typename _Key, typename _Compare, typename _Allocator>
526da49c 488 inline bool
ed540c0a
CJ
489 operator>(const multiset<_Key, _Compare, _Allocator>& __lhs,
490 const multiset<_Key, _Compare, _Allocator>& __rhs)
285b36d6
BK
491 { return __lhs._M_base() > __rhs._M_base(); }
492
493 template<typename _Key, typename _Compare, typename _Allocator>
494 void
ed540c0a
CJ
495 swap(multiset<_Key, _Compare, _Allocator>& __x,
496 multiset<_Key, _Compare, _Allocator>& __y)
285b36d6 497 { return __x.swap(__y); }
ed540c0a 498
45f388bb 499} // namespace __debug
3cbc7af0 500} // namespace std
285b36d6
BK
501
502#endif