]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/include/bits/stl_multiset.h
Add assertions to extract(const_iterator) functions
[thirdparty/gcc.git] / libstdc++-v3 / include / bits / stl_multiset.h
1 // Multiset implementation -*- C++ -*-
2
3 // Copyright (C) 2001-2016 Free Software Foundation, Inc.
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
8 // Free Software Foundation; either version 3, or (at your option)
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
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/>.
24
25 /*
26 *
27 * Copyright (c) 1994
28 * Hewlett-Packard Company
29 *
30 * Permission to use, copy, modify, distribute and sell this software
31 * and its documentation for any purpose is hereby granted without fee,
32 * provided that the above copyright notice appear in all copies and
33 * that both that copyright notice and this permission notice appear
34 * in supporting documentation. Hewlett-Packard Company makes no
35 * representations about the suitability of this software for any
36 * purpose. It is provided "as is" without express or implied warranty.
37 *
38 *
39 * Copyright (c) 1996
40 * Silicon Graphics Computer Systems, Inc.
41 *
42 * Permission to use, copy, modify, distribute and sell this software
43 * and its documentation for any purpose is hereby granted without fee,
44 * provided that the above copyright notice appear in all copies and
45 * that both that copyright notice and this permission notice appear
46 * in supporting documentation. Silicon Graphics makes no
47 * representations about the suitability of this software for any
48 * purpose. It is provided "as is" without express or implied warranty.
49 */
50
51 /** @file bits/stl_multiset.h
52 * This is an internal header file, included by other library headers.
53 * Do not attempt to use it directly. @headername{set}
54 */
55
56 #ifndef _STL_MULTISET_H
57 #define _STL_MULTISET_H 1
58
59 #include <bits/concept_check.h>
60 #if __cplusplus >= 201103L
61 #include <initializer_list>
62 #endif
63
64 namespace std _GLIBCXX_VISIBILITY(default)
65 {
66 _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
67
68 template<typename _Key, typename _Compare, typename _Alloc>
69 class set;
70
71 /**
72 * @brief A standard container made up of elements, which can be retrieved
73 * in logarithmic time.
74 *
75 * @ingroup associative_containers
76 *
77 *
78 * @tparam _Key Type of key objects.
79 * @tparam _Compare Comparison function object type, defaults to less<_Key>.
80 * @tparam _Alloc Allocator type, defaults to allocator<_Key>.
81 *
82 * Meets the requirements of a <a href="tables.html#65">container</a>, a
83 * <a href="tables.html#66">reversible container</a>, and an
84 * <a href="tables.html#69">associative container</a> (using equivalent
85 * keys). For a @c multiset<Key> the key_type and value_type are Key.
86 *
87 * Multisets support bidirectional iterators.
88 *
89 * The private tree data is declared exactly the same way for set and
90 * multiset; the distinction is made entirely in how the tree functions are
91 * called (*_unique versus *_equal, same as the standard).
92 */
93 template <typename _Key, typename _Compare = std::less<_Key>,
94 typename _Alloc = std::allocator<_Key> >
95 class multiset
96 {
97 // concept requirements
98 typedef typename _Alloc::value_type _Alloc_value_type;
99 __glibcxx_class_requires(_Key, _SGIAssignableConcept)
100 __glibcxx_class_requires4(_Compare, bool, _Key, _Key,
101 _BinaryFunctionConcept)
102 __glibcxx_class_requires2(_Key, _Alloc_value_type, _SameTypeConcept)
103
104 public:
105 // typedefs:
106 typedef _Key key_type;
107 typedef _Key value_type;
108 typedef _Compare key_compare;
109 typedef _Compare value_compare;
110 typedef _Alloc allocator_type;
111
112 private:
113 /// This turns a red-black tree into a [multi]set.
114 typedef typename __gnu_cxx::__alloc_traits<_Alloc>::template
115 rebind<_Key>::other _Key_alloc_type;
116
117 typedef _Rb_tree<key_type, value_type, _Identity<value_type>,
118 key_compare, _Key_alloc_type> _Rep_type;
119 /// The actual tree structure.
120 _Rep_type _M_t;
121
122 typedef __gnu_cxx::__alloc_traits<_Key_alloc_type> _Alloc_traits;
123
124 public:
125 typedef typename _Alloc_traits::pointer pointer;
126 typedef typename _Alloc_traits::const_pointer const_pointer;
127 typedef typename _Alloc_traits::reference reference;
128 typedef typename _Alloc_traits::const_reference const_reference;
129 // _GLIBCXX_RESOLVE_LIB_DEFECTS
130 // DR 103. set::iterator is required to be modifiable,
131 // but this allows modification of keys.
132 typedef typename _Rep_type::const_iterator iterator;
133 typedef typename _Rep_type::const_iterator const_iterator;
134 typedef typename _Rep_type::const_reverse_iterator reverse_iterator;
135 typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator;
136 typedef typename _Rep_type::size_type size_type;
137 typedef typename _Rep_type::difference_type difference_type;
138
139 #if __cplusplus > 201402L
140 using node_type = typename _Rep_type::node_type;
141 #endif
142
143 // allocation/deallocation
144 /**
145 * @brief Default constructor creates no elements.
146 */
147 multiset()
148 #if __cplusplus >= 201103L
149 noexcept(is_nothrow_default_constructible<allocator_type>::value)
150 #endif
151 : _M_t() { }
152
153 /**
154 * @brief Creates a %multiset with no elements.
155 * @param __comp Comparator to use.
156 * @param __a An allocator object.
157 */
158 explicit
159 multiset(const _Compare& __comp,
160 const allocator_type& __a = allocator_type())
161 : _M_t(__comp, _Key_alloc_type(__a)) { }
162
163 /**
164 * @brief Builds a %multiset from a range.
165 * @param __first An input iterator.
166 * @param __last An input iterator.
167 *
168 * Create a %multiset consisting of copies of the elements from
169 * [first,last). This is linear in N if the range is already sorted,
170 * and NlogN otherwise (where N is distance(__first,__last)).
171 */
172 template<typename _InputIterator>
173 multiset(_InputIterator __first, _InputIterator __last)
174 : _M_t()
175 { _M_t._M_insert_equal(__first, __last); }
176
177 /**
178 * @brief Builds a %multiset from a range.
179 * @param __first An input iterator.
180 * @param __last An input iterator.
181 * @param __comp A comparison functor.
182 * @param __a An allocator object.
183 *
184 * Create a %multiset consisting of copies of the elements from
185 * [__first,__last). This is linear in N if the range is already sorted,
186 * and NlogN otherwise (where N is distance(__first,__last)).
187 */
188 template<typename _InputIterator>
189 multiset(_InputIterator __first, _InputIterator __last,
190 const _Compare& __comp,
191 const allocator_type& __a = allocator_type())
192 : _M_t(__comp, _Key_alloc_type(__a))
193 { _M_t._M_insert_equal(__first, __last); }
194
195 /**
196 * @brief %Multiset copy constructor.
197 * @param __x A %multiset of identical element and allocator types.
198 *
199 * The newly-created %multiset uses a copy of the allocator object used
200 * by @a __x (unless the allocator traits dictate a different object).
201 */
202 multiset(const multiset& __x)
203 : _M_t(__x._M_t) { }
204
205 #if __cplusplus >= 201103L
206 /**
207 * @brief %Multiset move constructor.
208 * @param __x A %multiset of identical element and allocator types.
209 *
210 * The newly-created %multiset contains the exact contents of @a __x.
211 * The contents of @a __x are a valid, but unspecified %multiset.
212 */
213 multiset(multiset&& __x)
214 noexcept(is_nothrow_copy_constructible<_Compare>::value)
215 : _M_t(std::move(__x._M_t)) { }
216
217 /**
218 * @brief Builds a %multiset from an initializer_list.
219 * @param __l An initializer_list.
220 * @param __comp A comparison functor.
221 * @param __a An allocator object.
222 *
223 * Create a %multiset consisting of copies of the elements from
224 * the list. This is linear in N if the list is already sorted,
225 * and NlogN otherwise (where N is @a __l.size()).
226 */
227 multiset(initializer_list<value_type> __l,
228 const _Compare& __comp = _Compare(),
229 const allocator_type& __a = allocator_type())
230 : _M_t(__comp, _Key_alloc_type(__a))
231 { _M_t._M_insert_equal(__l.begin(), __l.end()); }
232
233 /// Allocator-extended default constructor.
234 explicit
235 multiset(const allocator_type& __a)
236 : _M_t(_Compare(), _Key_alloc_type(__a)) { }
237
238 /// Allocator-extended copy constructor.
239 multiset(const multiset& __m, const allocator_type& __a)
240 : _M_t(__m._M_t, _Key_alloc_type(__a)) { }
241
242 /// Allocator-extended move constructor.
243 multiset(multiset&& __m, const allocator_type& __a)
244 noexcept(is_nothrow_copy_constructible<_Compare>::value
245 && _Alloc_traits::_S_always_equal())
246 : _M_t(std::move(__m._M_t), _Key_alloc_type(__a)) { }
247
248 /// Allocator-extended initialier-list constructor.
249 multiset(initializer_list<value_type> __l, const allocator_type& __a)
250 : _M_t(_Compare(), _Key_alloc_type(__a))
251 { _M_t._M_insert_equal(__l.begin(), __l.end()); }
252
253 /// Allocator-extended range constructor.
254 template<typename _InputIterator>
255 multiset(_InputIterator __first, _InputIterator __last,
256 const allocator_type& __a)
257 : _M_t(_Compare(), _Key_alloc_type(__a))
258 { _M_t._M_insert_equal(__first, __last); }
259 #endif
260
261 /**
262 * @brief %Multiset assignment operator.
263 * @param __x A %multiset of identical element and allocator types.
264 *
265 * All the elements of @a __x are copied.
266 *
267 * Whether the allocator is copied depends on the allocator traits.
268 */
269 multiset&
270 operator=(const multiset& __x)
271 {
272 _M_t = __x._M_t;
273 return *this;
274 }
275
276 #if __cplusplus >= 201103L
277 /// Move assignment operator.
278 multiset&
279 operator=(multiset&&) = default;
280
281 /**
282 * @brief %Multiset list assignment operator.
283 * @param __l An initializer_list.
284 *
285 * This function fills a %multiset with copies of the elements in the
286 * initializer list @a __l.
287 *
288 * Note that the assignment completely changes the %multiset and
289 * that the resulting %multiset's size is the same as the number
290 * of elements assigned.
291 */
292 multiset&
293 operator=(initializer_list<value_type> __l)
294 {
295 _M_t._M_assign_equal(__l.begin(), __l.end());
296 return *this;
297 }
298 #endif
299
300 // accessors:
301
302 /// Returns the comparison object.
303 key_compare
304 key_comp() const
305 { return _M_t.key_comp(); }
306 /// Returns the comparison object.
307 value_compare
308 value_comp() const
309 { return _M_t.key_comp(); }
310 /// Returns the memory allocation object.
311 allocator_type
312 get_allocator() const _GLIBCXX_NOEXCEPT
313 { return allocator_type(_M_t.get_allocator()); }
314
315 /**
316 * Returns a read-only (constant) iterator that points to the first
317 * element in the %multiset. Iteration is done in ascending order
318 * according to the keys.
319 */
320 iterator
321 begin() const _GLIBCXX_NOEXCEPT
322 { return _M_t.begin(); }
323
324 /**
325 * Returns a read-only (constant) iterator that points one past the last
326 * element in the %multiset. Iteration is done in ascending order
327 * according to the keys.
328 */
329 iterator
330 end() const _GLIBCXX_NOEXCEPT
331 { return _M_t.end(); }
332
333 /**
334 * Returns a read-only (constant) reverse iterator that points to the
335 * last element in the %multiset. Iteration is done in descending order
336 * according to the keys.
337 */
338 reverse_iterator
339 rbegin() const _GLIBCXX_NOEXCEPT
340 { return _M_t.rbegin(); }
341
342 /**
343 * Returns a read-only (constant) reverse iterator that points to the
344 * last element in the %multiset. Iteration is done in descending order
345 * according to the keys.
346 */
347 reverse_iterator
348 rend() const _GLIBCXX_NOEXCEPT
349 { return _M_t.rend(); }
350
351 #if __cplusplus >= 201103L
352 /**
353 * Returns a read-only (constant) iterator that points to the first
354 * element in the %multiset. Iteration is done in ascending order
355 * according to the keys.
356 */
357 iterator
358 cbegin() const noexcept
359 { return _M_t.begin(); }
360
361 /**
362 * Returns a read-only (constant) iterator that points one past the last
363 * element in the %multiset. Iteration is done in ascending order
364 * according to the keys.
365 */
366 iterator
367 cend() const noexcept
368 { return _M_t.end(); }
369
370 /**
371 * Returns a read-only (constant) reverse iterator that points to the
372 * last element in the %multiset. Iteration is done in descending order
373 * according to the keys.
374 */
375 reverse_iterator
376 crbegin() const noexcept
377 { return _M_t.rbegin(); }
378
379 /**
380 * Returns a read-only (constant) reverse iterator that points to the
381 * last element in the %multiset. Iteration is done in descending order
382 * according to the keys.
383 */
384 reverse_iterator
385 crend() const noexcept
386 { return _M_t.rend(); }
387 #endif
388
389 /// Returns true if the %set is empty.
390 bool
391 empty() const _GLIBCXX_NOEXCEPT
392 { return _M_t.empty(); }
393
394 /// Returns the size of the %set.
395 size_type
396 size() const _GLIBCXX_NOEXCEPT
397 { return _M_t.size(); }
398
399 /// Returns the maximum size of the %set.
400 size_type
401 max_size() const _GLIBCXX_NOEXCEPT
402 { return _M_t.max_size(); }
403
404 /**
405 * @brief Swaps data with another %multiset.
406 * @param __x A %multiset of the same element and allocator types.
407 *
408 * This exchanges the elements between two multisets in constant time.
409 * (It is only swapping a pointer, an integer, and an instance of the @c
410 * Compare type (which itself is often stateless and empty), so it should
411 * be quite fast.)
412 * Note that the global std::swap() function is specialized such that
413 * std::swap(s1,s2) will feed to this function.
414 *
415 * Whether the allocators are swapped depends on the allocator traits.
416 */
417 void
418 swap(multiset& __x)
419 _GLIBCXX_NOEXCEPT_IF(__is_nothrow_swappable<_Compare>::value)
420 { _M_t.swap(__x._M_t); }
421
422 // insert/erase
423 #if __cplusplus >= 201103L
424 /**
425 * @brief Builds and inserts an element into the %multiset.
426 * @param __args Arguments used to generate the element instance to be
427 * inserted.
428 * @return An iterator that points to the inserted element.
429 *
430 * This function inserts an element into the %multiset. Contrary
431 * to a std::set the %multiset does not rely on unique keys and thus
432 * multiple copies of the same element can be inserted.
433 *
434 * Insertion requires logarithmic time.
435 */
436 template<typename... _Args>
437 iterator
438 emplace(_Args&&... __args)
439 { return _M_t._M_emplace_equal(std::forward<_Args>(__args)...); }
440
441 /**
442 * @brief Builds and inserts an element into the %multiset.
443 * @param __pos An iterator that serves as a hint as to where the
444 * element should be inserted.
445 * @param __args Arguments used to generate the element instance to be
446 * inserted.
447 * @return An iterator that points to the inserted element.
448 *
449 * This function inserts an element into the %multiset. Contrary
450 * to a std::set the %multiset does not rely on unique keys and thus
451 * multiple copies of the same element can be inserted.
452 *
453 * Note that the first parameter is only a hint and can potentially
454 * improve the performance of the insertion process. A bad hint would
455 * cause no gains in efficiency.
456 *
457 * See https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints
458 * for more on @a hinting.
459 *
460 * Insertion requires logarithmic time (if the hint is not taken).
461 */
462 template<typename... _Args>
463 iterator
464 emplace_hint(const_iterator __pos, _Args&&... __args)
465 {
466 return _M_t._M_emplace_hint_equal(__pos,
467 std::forward<_Args>(__args)...);
468 }
469 #endif
470
471 /**
472 * @brief Inserts an element into the %multiset.
473 * @param __x Element to be inserted.
474 * @return An iterator that points to the inserted element.
475 *
476 * This function inserts an element into the %multiset. Contrary
477 * to a std::set the %multiset does not rely on unique keys and thus
478 * multiple copies of the same element can be inserted.
479 *
480 * Insertion requires logarithmic time.
481 */
482 iterator
483 insert(const value_type& __x)
484 { return _M_t._M_insert_equal(__x); }
485
486 #if __cplusplus >= 201103L
487 iterator
488 insert(value_type&& __x)
489 { return _M_t._M_insert_equal(std::move(__x)); }
490 #endif
491
492 /**
493 * @brief Inserts an element into the %multiset.
494 * @param __position An iterator that serves as a hint as to where the
495 * element should be inserted.
496 * @param __x Element to be inserted.
497 * @return An iterator that points to the inserted element.
498 *
499 * This function inserts an element into the %multiset. Contrary
500 * to a std::set the %multiset does not rely on unique keys and thus
501 * multiple copies of the same element can be inserted.
502 *
503 * Note that the first parameter is only a hint and can potentially
504 * improve the performance of the insertion process. A bad hint would
505 * cause no gains in efficiency.
506 *
507 * See https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints
508 * for more on @a hinting.
509 *
510 * Insertion requires logarithmic time (if the hint is not taken).
511 */
512 iterator
513 insert(const_iterator __position, const value_type& __x)
514 { return _M_t._M_insert_equal_(__position, __x); }
515
516 #if __cplusplus >= 201103L
517 iterator
518 insert(const_iterator __position, value_type&& __x)
519 { return _M_t._M_insert_equal_(__position, std::move(__x)); }
520 #endif
521
522 /**
523 * @brief A template function that tries to insert a range of elements.
524 * @param __first Iterator pointing to the start of the range to be
525 * inserted.
526 * @param __last Iterator pointing to the end of the range.
527 *
528 * Complexity similar to that of the range constructor.
529 */
530 template<typename _InputIterator>
531 void
532 insert(_InputIterator __first, _InputIterator __last)
533 { _M_t._M_insert_equal(__first, __last); }
534
535 #if __cplusplus >= 201103L
536 /**
537 * @brief Attempts to insert a list of elements into the %multiset.
538 * @param __l A std::initializer_list<value_type> of elements
539 * to be inserted.
540 *
541 * Complexity similar to that of the range constructor.
542 */
543 void
544 insert(initializer_list<value_type> __l)
545 { this->insert(__l.begin(), __l.end()); }
546 #endif
547
548 #if __cplusplus > 201402L
549 /// Extract a node.
550 node_type
551 extract(const_iterator __pos)
552 {
553 __glibcxx_assert(__pos != end());
554 return _M_t.extract(__pos);
555 }
556
557 /// Extract a node.
558 node_type
559 extract(const key_type& __x)
560 { return _M_t.extract(__x); }
561
562 /// Re-insert an extracted node.
563 iterator
564 insert(node_type&& __nh)
565 { return _M_t._M_reinsert_node_equal(std::move(__nh)); }
566
567 /// Re-insert an extracted node.
568 iterator
569 insert(const_iterator __hint, node_type&& __nh)
570 { return _M_t._M_reinsert_node_hint_equal(__hint, std::move(__nh)); }
571
572 template<typename, typename>
573 friend class _Rb_tree_merge_helper;
574
575 template<typename _Compare1>
576 void
577 merge(multiset<_Key, _Compare1, _Alloc>& __source)
578 {
579 using _Merge_helper = _Rb_tree_merge_helper<multiset, _Compare1>;
580 _M_t._M_merge_equal(_Merge_helper::_S_get_tree(__source));
581 }
582
583 template<typename _Compare1>
584 void
585 merge(multiset<_Key, _Compare1, _Alloc>&& __source)
586 { merge(__source); }
587
588 template<typename _Compare1>
589 void
590 merge(set<_Key, _Compare1, _Alloc>& __source)
591 {
592 using _Merge_helper = _Rb_tree_merge_helper<multiset, _Compare1>;
593 _M_t._M_merge_equal(_Merge_helper::_S_get_tree(__source));
594 }
595
596 template<typename _Compare1>
597 void
598 merge(set<_Key, _Compare1, _Alloc>&& __source)
599 { merge(__source); }
600 #endif // C++17
601
602 #if __cplusplus >= 201103L
603 // _GLIBCXX_RESOLVE_LIB_DEFECTS
604 // DR 130. Associative erase should return an iterator.
605 /**
606 * @brief Erases an element from a %multiset.
607 * @param __position An iterator pointing to the element to be erased.
608 * @return An iterator pointing to the element immediately following
609 * @a position prior to the element being erased. If no such
610 * element exists, end() is returned.
611 *
612 * This function erases an element, pointed to by the given iterator,
613 * from a %multiset. Note that this function only erases the element,
614 * and that if the element is itself a pointer, the pointed-to memory is
615 * not touched in any way. Managing the pointer is the user's
616 * responsibility.
617 */
618 _GLIBCXX_ABI_TAG_CXX11
619 iterator
620 erase(const_iterator __position)
621 { return _M_t.erase(__position); }
622 #else
623 /**
624 * @brief Erases an element from a %multiset.
625 * @param __position An iterator pointing to the element to be erased.
626 *
627 * This function erases an element, pointed to by the given iterator,
628 * from a %multiset. Note that this function only erases the element,
629 * and that if the element is itself a pointer, the pointed-to memory is
630 * not touched in any way. Managing the pointer is the user's
631 * responsibility.
632 */
633 void
634 erase(iterator __position)
635 { _M_t.erase(__position); }
636 #endif
637
638 /**
639 * @brief Erases elements according to the provided key.
640 * @param __x Key of element to be erased.
641 * @return The number of elements erased.
642 *
643 * This function erases all elements located by the given key from a
644 * %multiset.
645 * Note that this function only erases the element, and that if
646 * the element is itself a pointer, the pointed-to memory is not touched
647 * in any way. Managing the pointer is the user's responsibility.
648 */
649 size_type
650 erase(const key_type& __x)
651 { return _M_t.erase(__x); }
652
653 #if __cplusplus >= 201103L
654 // _GLIBCXX_RESOLVE_LIB_DEFECTS
655 // DR 130. Associative erase should return an iterator.
656 /**
657 * @brief Erases a [first,last) range of elements from a %multiset.
658 * @param __first Iterator pointing to the start of the range to be
659 * erased.
660 * @param __last Iterator pointing to the end of the range to
661 * be erased.
662 * @return The iterator @a last.
663 *
664 * This function erases a sequence of elements from a %multiset.
665 * Note that this function only erases the elements, and that if
666 * the elements themselves are pointers, the pointed-to memory is not
667 * touched in any way. Managing the pointer is the user's
668 * responsibility.
669 */
670 _GLIBCXX_ABI_TAG_CXX11
671 iterator
672 erase(const_iterator __first, const_iterator __last)
673 { return _M_t.erase(__first, __last); }
674 #else
675 /**
676 * @brief Erases a [first,last) range of elements from a %multiset.
677 * @param first Iterator pointing to the start of the range to be
678 * erased.
679 * @param last Iterator pointing to the end of the range to be erased.
680 *
681 * This function erases a sequence of elements from a %multiset.
682 * Note that this function only erases the elements, and that if
683 * the elements themselves are pointers, the pointed-to memory is not
684 * touched in any way. Managing the pointer is the user's
685 * responsibility.
686 */
687 void
688 erase(iterator __first, iterator __last)
689 { _M_t.erase(__first, __last); }
690 #endif
691
692 /**
693 * Erases all elements in a %multiset. Note that this function only
694 * erases the elements, and that if the elements themselves are pointers,
695 * the pointed-to memory is not touched in any way. Managing the pointer
696 * is the user's responsibility.
697 */
698 void
699 clear() _GLIBCXX_NOEXCEPT
700 { _M_t.clear(); }
701
702 // multiset operations:
703
704 //@{
705 /**
706 * @brief Finds the number of elements with given key.
707 * @param __x Key of elements to be located.
708 * @return Number of elements with specified key.
709 */
710 size_type
711 count(const key_type& __x) const
712 { return _M_t.count(__x); }
713
714 #if __cplusplus > 201103L
715 template<typename _Kt>
716 auto
717 count(const _Kt& __x) const -> decltype(_M_t._M_count_tr(__x))
718 { return _M_t._M_count_tr(__x); }
719 #endif
720 //@}
721
722 // _GLIBCXX_RESOLVE_LIB_DEFECTS
723 // 214. set::find() missing const overload
724 //@{
725 /**
726 * @brief Tries to locate an element in a %set.
727 * @param __x Element to be located.
728 * @return Iterator pointing to sought-after element, or end() if not
729 * found.
730 *
731 * This function takes a key and tries to locate the element with which
732 * the key matches. If successful the function returns an iterator
733 * pointing to the sought after element. If unsuccessful it returns the
734 * past-the-end ( @c end() ) iterator.
735 */
736 iterator
737 find(const key_type& __x)
738 { return _M_t.find(__x); }
739
740 const_iterator
741 find(const key_type& __x) const
742 { return _M_t.find(__x); }
743
744 #if __cplusplus > 201103L
745 template<typename _Kt>
746 auto
747 find(const _Kt& __x)
748 -> decltype(iterator{_M_t._M_find_tr(__x)})
749 { return iterator{_M_t._M_find_tr(__x)}; }
750
751 template<typename _Kt>
752 auto
753 find(const _Kt& __x) const
754 -> decltype(const_iterator{_M_t._M_find_tr(__x)})
755 { return const_iterator{_M_t._M_find_tr(__x)}; }
756 #endif
757 //@}
758
759 //@{
760 /**
761 * @brief Finds the beginning of a subsequence matching given key.
762 * @param __x Key to be located.
763 * @return Iterator pointing to first element equal to or greater
764 * than key, or end().
765 *
766 * This function returns the first element of a subsequence of elements
767 * that matches the given key. If unsuccessful it returns an iterator
768 * pointing to the first element that has a greater value than given key
769 * or end() if no such element exists.
770 */
771 iterator
772 lower_bound(const key_type& __x)
773 { return _M_t.lower_bound(__x); }
774
775 const_iterator
776 lower_bound(const key_type& __x) const
777 { return _M_t.lower_bound(__x); }
778
779 #if __cplusplus > 201103L
780 template<typename _Kt>
781 auto
782 lower_bound(const _Kt& __x)
783 -> decltype(_M_t._M_lower_bound_tr(__x))
784 { return _M_t._M_lower_bound_tr(__x); }
785
786 template<typename _Kt>
787 auto
788 lower_bound(const _Kt& __x) const
789 -> decltype(_M_t._M_lower_bound_tr(__x))
790 { return _M_t._M_lower_bound_tr(__x); }
791 #endif
792 //@}
793
794 //@{
795 /**
796 * @brief Finds the end of a subsequence matching given key.
797 * @param __x Key to be located.
798 * @return Iterator pointing to the first element
799 * greater than key, or end().
800 */
801 iterator
802 upper_bound(const key_type& __x)
803 { return _M_t.upper_bound(__x); }
804
805 const_iterator
806 upper_bound(const key_type& __x) const
807 { return _M_t.upper_bound(__x); }
808
809 #if __cplusplus > 201103L
810 template<typename _Kt>
811 auto
812 upper_bound(const _Kt& __x)
813 -> decltype(_M_t._M_upper_bound_tr(__x))
814 { return _M_t._M_upper_bound_tr(__x); }
815
816 template<typename _Kt>
817 auto
818 upper_bound(const _Kt& __x) const
819 -> decltype(_M_t._M_upper_bound_tr(__x))
820 { return _M_t._M_upper_bound_tr(__x); }
821 #endif
822 //@}
823
824 //@{
825 /**
826 * @brief Finds a subsequence matching given key.
827 * @param __x Key to be located.
828 * @return Pair of iterators that possibly points to the subsequence
829 * matching given key.
830 *
831 * This function is equivalent to
832 * @code
833 * std::make_pair(c.lower_bound(val),
834 * c.upper_bound(val))
835 * @endcode
836 * (but is faster than making the calls separately).
837 *
838 * This function probably only makes sense for multisets.
839 */
840 std::pair<iterator, iterator>
841 equal_range(const key_type& __x)
842 { return _M_t.equal_range(__x); }
843
844 std::pair<const_iterator, const_iterator>
845 equal_range(const key_type& __x) const
846 { return _M_t.equal_range(__x); }
847
848 #if __cplusplus > 201103L
849 template<typename _Kt>
850 auto
851 equal_range(const _Kt& __x)
852 -> decltype(_M_t._M_equal_range_tr(__x))
853 { return _M_t._M_equal_range_tr(__x); }
854
855 template<typename _Kt>
856 auto
857 equal_range(const _Kt& __x) const
858 -> decltype(_M_t._M_equal_range_tr(__x))
859 { return _M_t._M_equal_range_tr(__x); }
860 #endif
861 //@}
862
863 template<typename _K1, typename _C1, typename _A1>
864 friend bool
865 operator==(const multiset<_K1, _C1, _A1>&,
866 const multiset<_K1, _C1, _A1>&);
867
868 template<typename _K1, typename _C1, typename _A1>
869 friend bool
870 operator< (const multiset<_K1, _C1, _A1>&,
871 const multiset<_K1, _C1, _A1>&);
872 };
873
874 /**
875 * @brief Multiset equality comparison.
876 * @param __x A %multiset.
877 * @param __y A %multiset of the same type as @a __x.
878 * @return True iff the size and elements of the multisets are equal.
879 *
880 * This is an equivalence relation. It is linear in the size of the
881 * multisets.
882 * Multisets are considered equivalent if their sizes are equal, and if
883 * corresponding elements compare equal.
884 */
885 template<typename _Key, typename _Compare, typename _Alloc>
886 inline bool
887 operator==(const multiset<_Key, _Compare, _Alloc>& __x,
888 const multiset<_Key, _Compare, _Alloc>& __y)
889 { return __x._M_t == __y._M_t; }
890
891 /**
892 * @brief Multiset ordering relation.
893 * @param __x A %multiset.
894 * @param __y A %multiset of the same type as @a __x.
895 * @return True iff @a __x is lexicographically less than @a __y.
896 *
897 * This is a total ordering relation. It is linear in the size of the
898 * sets. The elements must be comparable with @c <.
899 *
900 * See std::lexicographical_compare() for how the determination is made.
901 */
902 template<typename _Key, typename _Compare, typename _Alloc>
903 inline bool
904 operator<(const multiset<_Key, _Compare, _Alloc>& __x,
905 const multiset<_Key, _Compare, _Alloc>& __y)
906 { return __x._M_t < __y._M_t; }
907
908 /// Returns !(x == y).
909 template<typename _Key, typename _Compare, typename _Alloc>
910 inline bool
911 operator!=(const multiset<_Key, _Compare, _Alloc>& __x,
912 const multiset<_Key, _Compare, _Alloc>& __y)
913 { return !(__x == __y); }
914
915 /// Returns y < x.
916 template<typename _Key, typename _Compare, typename _Alloc>
917 inline bool
918 operator>(const multiset<_Key,_Compare,_Alloc>& __x,
919 const multiset<_Key,_Compare,_Alloc>& __y)
920 { return __y < __x; }
921
922 /// Returns !(y < x)
923 template<typename _Key, typename _Compare, typename _Alloc>
924 inline bool
925 operator<=(const multiset<_Key, _Compare, _Alloc>& __x,
926 const multiset<_Key, _Compare, _Alloc>& __y)
927 { return !(__y < __x); }
928
929 /// Returns !(x < y)
930 template<typename _Key, typename _Compare, typename _Alloc>
931 inline bool
932 operator>=(const multiset<_Key, _Compare, _Alloc>& __x,
933 const multiset<_Key, _Compare, _Alloc>& __y)
934 { return !(__x < __y); }
935
936 /// See std::multiset::swap().
937 template<typename _Key, typename _Compare, typename _Alloc>
938 inline void
939 swap(multiset<_Key, _Compare, _Alloc>& __x,
940 multiset<_Key, _Compare, _Alloc>& __y)
941 _GLIBCXX_NOEXCEPT_IF(noexcept(__x.swap(__y)))
942 { __x.swap(__y); }
943
944 _GLIBCXX_END_NAMESPACE_CONTAINER
945
946 #if __cplusplus > 201402L
947 _GLIBCXX_BEGIN_NAMESPACE_VERSION
948 // Allow std::multiset access to internals of compatible sets.
949 template<typename _Val, typename _Cmp1, typename _Alloc, typename _Cmp2>
950 struct
951 _Rb_tree_merge_helper<_GLIBCXX_STD_C::multiset<_Val, _Cmp1, _Alloc>,
952 _Cmp2>
953 {
954 private:
955 friend class _GLIBCXX_STD_C::multiset<_Val, _Cmp1, _Alloc>;
956
957 static auto&
958 _S_get_tree(_GLIBCXX_STD_C::set<_Val, _Cmp2, _Alloc>& __set)
959 { return __set._M_t; }
960
961 static auto&
962 _S_get_tree(_GLIBCXX_STD_C::multiset<_Val, _Cmp2, _Alloc>& __set)
963 { return __set._M_t; }
964 };
965 _GLIBCXX_END_NAMESPACE_VERSION
966 #endif // C++17
967
968 } // namespace std
969
970 #endif /* _STL_MULTISET_H */