]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/include/bits/stl_multiset.h
re PR libstdc++/29988 (More stl_tree.h enhancements: improving operator=)
[thirdparty/gcc.git] / libstdc++-v3 / include / bits / stl_multiset.h
1 // Multiset implementation -*- C++ -*-
2
3 // Copyright (C) 2001-2014 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 /**
69 * @brief A standard container made up of elements, which can be retrieved
70 * in logarithmic time.
71 *
72 * @ingroup associative_containers
73 *
74 *
75 * @tparam _Key Type of key objects.
76 * @tparam _Compare Comparison function object type, defaults to less<_Key>.
77 * @tparam _Alloc Allocator type, defaults to allocator<_Key>.
78 *
79 * Meets the requirements of a <a href="tables.html#65">container</a>, a
80 * <a href="tables.html#66">reversible container</a>, and an
81 * <a href="tables.html#69">associative container</a> (using equivalent
82 * keys). For a @c multiset<Key> the key_type and value_type are Key.
83 *
84 * Multisets support bidirectional iterators.
85 *
86 * The private tree data is declared exactly the same way for set and
87 * multiset; the distinction is made entirely in how the tree functions are
88 * called (*_unique versus *_equal, same as the standard).
89 */
90 template <typename _Key, typename _Compare = std::less<_Key>,
91 typename _Alloc = std::allocator<_Key> >
92 class multiset
93 {
94 // concept requirements
95 typedef typename _Alloc::value_type _Alloc_value_type;
96 __glibcxx_class_requires(_Key, _SGIAssignableConcept)
97 __glibcxx_class_requires4(_Compare, bool, _Key, _Key,
98 _BinaryFunctionConcept)
99 __glibcxx_class_requires2(_Key, _Alloc_value_type, _SameTypeConcept)
100
101 public:
102 // typedefs:
103 typedef _Key key_type;
104 typedef _Key value_type;
105 typedef _Compare key_compare;
106 typedef _Compare value_compare;
107 typedef _Alloc allocator_type;
108
109 private:
110 /// This turns a red-black tree into a [multi]set.
111 typedef typename __gnu_cxx::__alloc_traits<_Alloc>::template
112 rebind<_Key>::other _Key_alloc_type;
113
114 typedef _Rb_tree<key_type, value_type, _Identity<value_type>,
115 key_compare, _Key_alloc_type> _Rep_type;
116 /// The actual tree structure.
117 _Rep_type _M_t;
118
119 typedef __gnu_cxx::__alloc_traits<_Key_alloc_type> _Alloc_traits;
120
121 public:
122 typedef typename _Alloc_traits::pointer pointer;
123 typedef typename _Alloc_traits::const_pointer const_pointer;
124 typedef typename _Alloc_traits::reference reference;
125 typedef typename _Alloc_traits::const_reference const_reference;
126 // _GLIBCXX_RESOLVE_LIB_DEFECTS
127 // DR 103. set::iterator is required to be modifiable,
128 // but this allows modification of keys.
129 typedef typename _Rep_type::const_iterator iterator;
130 typedef typename _Rep_type::const_iterator const_iterator;
131 typedef typename _Rep_type::const_reverse_iterator reverse_iterator;
132 typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator;
133 typedef typename _Rep_type::size_type size_type;
134 typedef typename _Rep_type::difference_type difference_type;
135
136 // allocation/deallocation
137 /**
138 * @brief Default constructor creates no elements.
139 */
140 multiset()
141 : _M_t() { }
142
143 /**
144 * @brief Creates a %multiset with no elements.
145 * @param __comp Comparator to use.
146 * @param __a An allocator object.
147 */
148 explicit
149 multiset(const _Compare& __comp,
150 const allocator_type& __a = allocator_type())
151 : _M_t(__comp, _Key_alloc_type(__a)) { }
152
153 /**
154 * @brief Builds a %multiset from a range.
155 * @param __first An input iterator.
156 * @param __last An input iterator.
157 *
158 * Create a %multiset consisting of copies of the elements from
159 * [first,last). This is linear in N if the range is already sorted,
160 * and NlogN otherwise (where N is distance(__first,__last)).
161 */
162 template<typename _InputIterator>
163 multiset(_InputIterator __first, _InputIterator __last)
164 : _M_t()
165 { _M_t._M_insert_equal(__first, __last); }
166
167 /**
168 * @brief Builds a %multiset from a range.
169 * @param __first An input iterator.
170 * @param __last An input iterator.
171 * @param __comp A comparison functor.
172 * @param __a An allocator object.
173 *
174 * Create a %multiset consisting of copies of the elements from
175 * [__first,__last). This is linear in N if the range is already sorted,
176 * and NlogN otherwise (where N is distance(__first,__last)).
177 */
178 template<typename _InputIterator>
179 multiset(_InputIterator __first, _InputIterator __last,
180 const _Compare& __comp,
181 const allocator_type& __a = allocator_type())
182 : _M_t(__comp, _Key_alloc_type(__a))
183 { _M_t._M_insert_equal(__first, __last); }
184
185 /**
186 * @brief %Multiset copy constructor.
187 * @param __x A %multiset of identical element and allocator types.
188 *
189 * The newly-created %multiset uses a copy of the allocation object used
190 * by @a __x.
191 */
192 multiset(const multiset& __x)
193 : _M_t(__x._M_t) { }
194
195 #if __cplusplus >= 201103L
196 /**
197 * @brief %Multiset move constructor.
198 * @param __x A %multiset of identical element and allocator types.
199 *
200 * The newly-created %multiset contains the exact contents of @a __x.
201 * The contents of @a __x are a valid, but unspecified %multiset.
202 */
203 multiset(multiset&& __x)
204 noexcept(is_nothrow_copy_constructible<_Compare>::value)
205 : _M_t(std::move(__x._M_t)) { }
206
207 /**
208 * @brief Builds a %multiset from an initializer_list.
209 * @param __l An initializer_list.
210 * @param __comp A comparison functor.
211 * @param __a An allocator object.
212 *
213 * Create a %multiset consisting of copies of the elements from
214 * the list. This is linear in N if the list is already sorted,
215 * and NlogN otherwise (where N is @a __l.size()).
216 */
217 multiset(initializer_list<value_type> __l,
218 const _Compare& __comp = _Compare(),
219 const allocator_type& __a = allocator_type())
220 : _M_t(__comp, _Key_alloc_type(__a))
221 { _M_t._M_insert_equal(__l.begin(), __l.end()); }
222
223 /// Allocator-extended default constructor.
224 explicit
225 multiset(const allocator_type& __a)
226 : _M_t(_Compare(), _Key_alloc_type(__a)) { }
227
228 /// Allocator-extended copy constructor.
229 multiset(const multiset& __m, const allocator_type& __a)
230 : _M_t(__m._M_t, _Key_alloc_type(__a)) { }
231
232 /// Allocator-extended move constructor.
233 multiset(multiset&& __m, const allocator_type& __a)
234 noexcept(is_nothrow_copy_constructible<_Compare>::value
235 && _Alloc_traits::_S_always_equal())
236 : _M_t(std::move(__m._M_t), _Key_alloc_type(__a)) { }
237
238 /// Allocator-extended initialier-list constructor.
239 multiset(initializer_list<value_type> __l, const allocator_type& __a)
240 : _M_t(_Compare(), _Key_alloc_type(__a))
241 { _M_t._M_insert_equal(__l.begin(), __l.end()); }
242
243 /// Allocator-extended range constructor.
244 template<typename _InputIterator>
245 multiset(_InputIterator __first, _InputIterator __last,
246 const allocator_type& __a)
247 : _M_t(_Compare(), _Key_alloc_type(__a))
248 { _M_t._M_insert_equal(__first, __last); }
249 #endif
250
251 /**
252 * @brief %Multiset assignment operator.
253 * @param __x A %multiset of identical element and allocator types.
254 *
255 * All the elements of @a __x are copied, but unlike the copy
256 * constructor, the allocator object is not copied.
257 */
258 multiset&
259 operator=(const multiset& __x)
260 {
261 _M_t = __x._M_t;
262 return *this;
263 }
264
265 #if __cplusplus >= 201103L
266 /// Move assignment operator.
267 multiset&
268 operator=(multiset&&) = default;
269
270 /**
271 * @brief %Multiset list assignment operator.
272 * @param __l An initializer_list.
273 *
274 * This function fills a %multiset with copies of the elements in the
275 * initializer list @a __l.
276 *
277 * Note that the assignment completely changes the %multiset and
278 * that the resulting %multiset's size is the same as the number
279 * of elements assigned. Old data may be lost.
280 */
281 multiset&
282 operator=(initializer_list<value_type> __l)
283 {
284 _M_t._M_assign_equal(__l.begin(), __l.end());
285 return *this;
286 }
287 #endif
288
289 // accessors:
290
291 /// Returns the comparison object.
292 key_compare
293 key_comp() const
294 { return _M_t.key_comp(); }
295 /// Returns the comparison object.
296 value_compare
297 value_comp() const
298 { return _M_t.key_comp(); }
299 /// Returns the memory allocation object.
300 allocator_type
301 get_allocator() const _GLIBCXX_NOEXCEPT
302 { return allocator_type(_M_t.get_allocator()); }
303
304 /**
305 * Returns a read-only (constant) iterator that points to the first
306 * element in the %multiset. Iteration is done in ascending order
307 * according to the keys.
308 */
309 iterator
310 begin() const _GLIBCXX_NOEXCEPT
311 { return _M_t.begin(); }
312
313 /**
314 * Returns a read-only (constant) iterator that points one past the last
315 * element in the %multiset. Iteration is done in ascending order
316 * according to the keys.
317 */
318 iterator
319 end() const _GLIBCXX_NOEXCEPT
320 { return _M_t.end(); }
321
322 /**
323 * Returns a read-only (constant) reverse iterator that points to the
324 * last element in the %multiset. Iteration is done in descending order
325 * according to the keys.
326 */
327 reverse_iterator
328 rbegin() const _GLIBCXX_NOEXCEPT
329 { return _M_t.rbegin(); }
330
331 /**
332 * Returns a read-only (constant) reverse iterator that points to the
333 * last element in the %multiset. Iteration is done in descending order
334 * according to the keys.
335 */
336 reverse_iterator
337 rend() const _GLIBCXX_NOEXCEPT
338 { return _M_t.rend(); }
339
340 #if __cplusplus >= 201103L
341 /**
342 * Returns a read-only (constant) iterator that points to the first
343 * element in the %multiset. Iteration is done in ascending order
344 * according to the keys.
345 */
346 iterator
347 cbegin() const noexcept
348 { return _M_t.begin(); }
349
350 /**
351 * Returns a read-only (constant) iterator that points one past the last
352 * element in the %multiset. Iteration is done in ascending order
353 * according to the keys.
354 */
355 iterator
356 cend() const noexcept
357 { return _M_t.end(); }
358
359 /**
360 * Returns a read-only (constant) reverse iterator that points to the
361 * last element in the %multiset. Iteration is done in descending order
362 * according to the keys.
363 */
364 reverse_iterator
365 crbegin() const noexcept
366 { return _M_t.rbegin(); }
367
368 /**
369 * Returns a read-only (constant) reverse iterator that points to the
370 * last element in the %multiset. Iteration is done in descending order
371 * according to the keys.
372 */
373 reverse_iterator
374 crend() const noexcept
375 { return _M_t.rend(); }
376 #endif
377
378 /// Returns true if the %set is empty.
379 bool
380 empty() const _GLIBCXX_NOEXCEPT
381 { return _M_t.empty(); }
382
383 /// Returns the size of the %set.
384 size_type
385 size() const _GLIBCXX_NOEXCEPT
386 { return _M_t.size(); }
387
388 /// Returns the maximum size of the %set.
389 size_type
390 max_size() const _GLIBCXX_NOEXCEPT
391 { return _M_t.max_size(); }
392
393 /**
394 * @brief Swaps data with another %multiset.
395 * @param __x A %multiset of the same element and allocator types.
396 *
397 * This exchanges the elements between two multisets in constant time.
398 * (It is only swapping a pointer, an integer, and an instance of the @c
399 * Compare type (which itself is often stateless and empty), so it should
400 * be quite fast.)
401 * Note that the global std::swap() function is specialized such that
402 * std::swap(s1,s2) will feed to this function.
403 */
404 void
405 swap(multiset& __x)
406 #if __cplusplus >= 201103L
407 noexcept(_Alloc_traits::_S_nothrow_swap())
408 #endif
409 { _M_t.swap(__x._M_t); }
410
411 // insert/erase
412 #if __cplusplus >= 201103L
413 /**
414 * @brief Builds and inserts an element into the %multiset.
415 * @param __args Arguments used to generate the element instance to be
416 * inserted.
417 * @return An iterator that points to the inserted element.
418 *
419 * This function inserts an element into the %multiset. Contrary
420 * to a std::set the %multiset does not rely on unique keys and thus
421 * multiple copies of the same element can be inserted.
422 *
423 * Insertion requires logarithmic time.
424 */
425 template<typename... _Args>
426 iterator
427 emplace(_Args&&... __args)
428 { return _M_t._M_emplace_equal(std::forward<_Args>(__args)...); }
429
430 /**
431 * @brief Builds and inserts an element into the %multiset.
432 * @param __pos An iterator that serves as a hint as to where the
433 * element should be inserted.
434 * @param __args Arguments used to generate the element instance to be
435 * inserted.
436 * @return An iterator that points to the inserted element.
437 *
438 * This function inserts an element into the %multiset. Contrary
439 * to a std::set the %multiset does not rely on unique keys and thus
440 * multiple copies of the same element can be inserted.
441 *
442 * Note that the first parameter is only a hint and can potentially
443 * improve the performance of the insertion process. A bad hint would
444 * cause no gains in efficiency.
445 *
446 * See https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints
447 * for more on @a hinting.
448 *
449 * Insertion requires logarithmic time (if the hint is not taken).
450 */
451 template<typename... _Args>
452 iterator
453 emplace_hint(const_iterator __pos, _Args&&... __args)
454 {
455 return _M_t._M_emplace_hint_equal(__pos,
456 std::forward<_Args>(__args)...);
457 }
458 #endif
459
460 /**
461 * @brief Inserts an element into the %multiset.
462 * @param __x Element to be inserted.
463 * @return An iterator that points to the inserted element.
464 *
465 * This function inserts an element into the %multiset. Contrary
466 * to a std::set the %multiset does not rely on unique keys and thus
467 * multiple copies of the same element can be inserted.
468 *
469 * Insertion requires logarithmic time.
470 */
471 iterator
472 insert(const value_type& __x)
473 { return _M_t._M_insert_equal(__x); }
474
475 #if __cplusplus >= 201103L
476 iterator
477 insert(value_type&& __x)
478 { return _M_t._M_insert_equal(std::move(__x)); }
479 #endif
480
481 /**
482 * @brief Inserts an element into the %multiset.
483 * @param __position An iterator that serves as a hint as to where the
484 * element should be inserted.
485 * @param __x Element to be inserted.
486 * @return An iterator that points to the inserted element.
487 *
488 * This function inserts an element into the %multiset. Contrary
489 * to a std::set the %multiset does not rely on unique keys and thus
490 * multiple copies of the same element can be inserted.
491 *
492 * Note that the first parameter is only a hint and can potentially
493 * improve the performance of the insertion process. A bad hint would
494 * cause no gains in efficiency.
495 *
496 * See https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints
497 * for more on @a hinting.
498 *
499 * Insertion requires logarithmic time (if the hint is not taken).
500 */
501 iterator
502 insert(const_iterator __position, const value_type& __x)
503 { return _M_t._M_insert_equal_(__position, __x); }
504
505 #if __cplusplus >= 201103L
506 iterator
507 insert(const_iterator __position, value_type&& __x)
508 { return _M_t._M_insert_equal_(__position, std::move(__x)); }
509 #endif
510
511 /**
512 * @brief A template function that tries to insert a range of elements.
513 * @param __first Iterator pointing to the start of the range to be
514 * inserted.
515 * @param __last Iterator pointing to the end of the range.
516 *
517 * Complexity similar to that of the range constructor.
518 */
519 template<typename _InputIterator>
520 void
521 insert(_InputIterator __first, _InputIterator __last)
522 { _M_t._M_insert_equal(__first, __last); }
523
524 #if __cplusplus >= 201103L
525 /**
526 * @brief Attempts to insert a list of elements into the %multiset.
527 * @param __l A std::initializer_list<value_type> of elements
528 * to be inserted.
529 *
530 * Complexity similar to that of the range constructor.
531 */
532 void
533 insert(initializer_list<value_type> __l)
534 { this->insert(__l.begin(), __l.end()); }
535 #endif
536
537 #if __cplusplus >= 201103L
538 // _GLIBCXX_RESOLVE_LIB_DEFECTS
539 // DR 130. Associative erase should return an iterator.
540 /**
541 * @brief Erases an element from a %multiset.
542 * @param __position An iterator pointing to the element to be erased.
543 * @return An iterator pointing to the element immediately following
544 * @a position prior to the element being erased. If no such
545 * element exists, end() is returned.
546 *
547 * This function erases an element, pointed to by the given iterator,
548 * from a %multiset. Note that this function only erases the element,
549 * and that if the element is itself a pointer, the pointed-to memory is
550 * not touched in any way. Managing the pointer is the user's
551 * responsibility.
552 */
553 _GLIBCXX_ABI_TAG_CXX11
554 iterator
555 erase(const_iterator __position)
556 { return _M_t.erase(__position); }
557 #else
558 /**
559 * @brief Erases an element from a %multiset.
560 * @param __position An iterator pointing to the element to be erased.
561 *
562 * This function erases an element, pointed to by the given iterator,
563 * from a %multiset. Note that this function only erases the element,
564 * and that if the element is itself a pointer, the pointed-to memory is
565 * not touched in any way. Managing the pointer is the user's
566 * responsibility.
567 */
568 void
569 erase(iterator __position)
570 { _M_t.erase(__position); }
571 #endif
572
573 /**
574 * @brief Erases elements according to the provided key.
575 * @param __x Key of element to be erased.
576 * @return The number of elements erased.
577 *
578 * This function erases all elements located by the given key from a
579 * %multiset.
580 * Note that this function only erases the element, and that if
581 * the element is itself a pointer, the pointed-to memory is not touched
582 * in any way. Managing the pointer is the user's responsibility.
583 */
584 size_type
585 erase(const key_type& __x)
586 { return _M_t.erase(__x); }
587
588 #if __cplusplus >= 201103L
589 // _GLIBCXX_RESOLVE_LIB_DEFECTS
590 // DR 130. Associative erase should return an iterator.
591 /**
592 * @brief Erases a [first,last) range of elements from a %multiset.
593 * @param __first Iterator pointing to the start of the range to be
594 * erased.
595 * @param __last Iterator pointing to the end of the range to
596 * be erased.
597 * @return The iterator @a last.
598 *
599 * This function erases a sequence of elements from a %multiset.
600 * Note that this function only erases the elements, and that if
601 * the elements themselves are pointers, the pointed-to memory is not
602 * touched in any way. Managing the pointer is the user's
603 * responsibility.
604 */
605 _GLIBCXX_ABI_TAG_CXX11
606 iterator
607 erase(const_iterator __first, const_iterator __last)
608 { return _M_t.erase(__first, __last); }
609 #else
610 /**
611 * @brief Erases a [first,last) range of elements from a %multiset.
612 * @param first Iterator pointing to the start of the range to be
613 * erased.
614 * @param last Iterator pointing to the end of the range to be erased.
615 *
616 * This function erases a sequence of elements from a %multiset.
617 * Note that this function only erases the elements, and that if
618 * the elements themselves are pointers, the pointed-to memory is not
619 * touched in any way. Managing the pointer is the user's
620 * responsibility.
621 */
622 void
623 erase(iterator __first, iterator __last)
624 { _M_t.erase(__first, __last); }
625 #endif
626
627 /**
628 * Erases all elements in a %multiset. Note that this function only
629 * erases the elements, and that if the elements themselves are pointers,
630 * the pointed-to memory is not touched in any way. Managing the pointer
631 * is the user's responsibility.
632 */
633 void
634 clear() _GLIBCXX_NOEXCEPT
635 { _M_t.clear(); }
636
637 // multiset operations:
638
639 /**
640 * @brief Finds the number of elements with given key.
641 * @param __x Key of elements to be located.
642 * @return Number of elements with specified key.
643 */
644 size_type
645 count(const key_type& __x) const
646 { return _M_t.count(__x); }
647
648 // _GLIBCXX_RESOLVE_LIB_DEFECTS
649 // 214. set::find() missing const overload
650 //@{
651 /**
652 * @brief Tries to locate an element in a %set.
653 * @param __x Element to be located.
654 * @return Iterator pointing to sought-after element, or end() if not
655 * found.
656 *
657 * This function takes a key and tries to locate the element with which
658 * the key matches. If successful the function returns an iterator
659 * pointing to the sought after element. If unsuccessful it returns the
660 * past-the-end ( @c end() ) iterator.
661 */
662 iterator
663 find(const key_type& __x)
664 { return _M_t.find(__x); }
665
666 const_iterator
667 find(const key_type& __x) const
668 { return _M_t.find(__x); }
669 //@}
670
671 //@{
672 /**
673 * @brief Finds the beginning of a subsequence matching given key.
674 * @param __x Key to be located.
675 * @return Iterator pointing to first element equal to or greater
676 * than key, or end().
677 *
678 * This function returns the first element of a subsequence of elements
679 * that matches the given key. If unsuccessful it returns an iterator
680 * pointing to the first element that has a greater value than given key
681 * or end() if no such element exists.
682 */
683 iterator
684 lower_bound(const key_type& __x)
685 { return _M_t.lower_bound(__x); }
686
687 const_iterator
688 lower_bound(const key_type& __x) const
689 { return _M_t.lower_bound(__x); }
690 //@}
691
692 //@{
693 /**
694 * @brief Finds the end of a subsequence matching given key.
695 * @param __x Key to be located.
696 * @return Iterator pointing to the first element
697 * greater than key, or end().
698 */
699 iterator
700 upper_bound(const key_type& __x)
701 { return _M_t.upper_bound(__x); }
702
703 const_iterator
704 upper_bound(const key_type& __x) const
705 { return _M_t.upper_bound(__x); }
706 //@}
707
708 //@{
709 /**
710 * @brief Finds a subsequence matching given key.
711 * @param __x Key to be located.
712 * @return Pair of iterators that possibly points to the subsequence
713 * matching given key.
714 *
715 * This function is equivalent to
716 * @code
717 * std::make_pair(c.lower_bound(val),
718 * c.upper_bound(val))
719 * @endcode
720 * (but is faster than making the calls separately).
721 *
722 * This function probably only makes sense for multisets.
723 */
724 std::pair<iterator, iterator>
725 equal_range(const key_type& __x)
726 { return _M_t.equal_range(__x); }
727
728 std::pair<const_iterator, const_iterator>
729 equal_range(const key_type& __x) const
730 { return _M_t.equal_range(__x); }
731 //@}
732
733 template<typename _K1, typename _C1, typename _A1>
734 friend bool
735 operator==(const multiset<_K1, _C1, _A1>&,
736 const multiset<_K1, _C1, _A1>&);
737
738 template<typename _K1, typename _C1, typename _A1>
739 friend bool
740 operator< (const multiset<_K1, _C1, _A1>&,
741 const multiset<_K1, _C1, _A1>&);
742 };
743
744 /**
745 * @brief Multiset equality comparison.
746 * @param __x A %multiset.
747 * @param __y A %multiset of the same type as @a __x.
748 * @return True iff the size and elements of the multisets are equal.
749 *
750 * This is an equivalence relation. It is linear in the size of the
751 * multisets.
752 * Multisets are considered equivalent if their sizes are equal, and if
753 * corresponding elements compare equal.
754 */
755 template<typename _Key, typename _Compare, typename _Alloc>
756 inline bool
757 operator==(const multiset<_Key, _Compare, _Alloc>& __x,
758 const multiset<_Key, _Compare, _Alloc>& __y)
759 { return __x._M_t == __y._M_t; }
760
761 /**
762 * @brief Multiset ordering relation.
763 * @param __x A %multiset.
764 * @param __y A %multiset of the same type as @a __x.
765 * @return True iff @a __x is lexicographically less than @a __y.
766 *
767 * This is a total ordering relation. It is linear in the size of the
768 * sets. The elements must be comparable with @c <.
769 *
770 * See std::lexicographical_compare() for how the determination is made.
771 */
772 template<typename _Key, typename _Compare, typename _Alloc>
773 inline bool
774 operator<(const multiset<_Key, _Compare, _Alloc>& __x,
775 const multiset<_Key, _Compare, _Alloc>& __y)
776 { return __x._M_t < __y._M_t; }
777
778 /// Returns !(x == y).
779 template<typename _Key, typename _Compare, typename _Alloc>
780 inline bool
781 operator!=(const multiset<_Key, _Compare, _Alloc>& __x,
782 const multiset<_Key, _Compare, _Alloc>& __y)
783 { return !(__x == __y); }
784
785 /// Returns y < x.
786 template<typename _Key, typename _Compare, typename _Alloc>
787 inline bool
788 operator>(const multiset<_Key,_Compare,_Alloc>& __x,
789 const multiset<_Key,_Compare,_Alloc>& __y)
790 { return __y < __x; }
791
792 /// Returns !(y < x)
793 template<typename _Key, typename _Compare, typename _Alloc>
794 inline bool
795 operator<=(const multiset<_Key, _Compare, _Alloc>& __x,
796 const multiset<_Key, _Compare, _Alloc>& __y)
797 { return !(__y < __x); }
798
799 /// Returns !(x < y)
800 template<typename _Key, typename _Compare, typename _Alloc>
801 inline bool
802 operator>=(const multiset<_Key, _Compare, _Alloc>& __x,
803 const multiset<_Key, _Compare, _Alloc>& __y)
804 { return !(__x < __y); }
805
806 /// See std::multiset::swap().
807 template<typename _Key, typename _Compare, typename _Alloc>
808 inline void
809 swap(multiset<_Key, _Compare, _Alloc>& __x,
810 multiset<_Key, _Compare, _Alloc>& __y)
811 { __x.swap(__y); }
812
813 _GLIBCXX_END_NAMESPACE_CONTAINER
814 } // namespace std
815
816 #endif /* _STL_MULTISET_H */