libstdc++
stl_multiset.h
Go to the documentation of this file.
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.
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 
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;
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  */
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  */
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  /**
267  * @brief %Multiset move assignment operator.
268  * @param __x A %multiset of identical element and allocator types.
269  *
270  * The contents of @a __x are moved into this %multiset (without
271  * copying if the allocators compare equal or get moved on assignment).
272  * Afterwards @a __x is in a valid, but unspecified state.
273  */
274  multiset&
275  operator=(multiset&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
276  {
277  if (!_M_t._M_move_assign(__x._M_t))
278  {
279  // The rvalue's allocator cannot be moved and is not equal,
280  // so we need to individually move each element.
281  clear();
282  insert(std::__make_move_if_noexcept_iterator(__x._M_t.begin()),
283  std::__make_move_if_noexcept_iterator(__x._M_t.end()));
284  __x.clear();
285  }
286  return *this;
287  }
288 
289  /**
290  * @brief %Multiset list assignment operator.
291  * @param __l An initializer_list.
292  *
293  * This function fills a %multiset with copies of the elements in the
294  * initializer list @a __l.
295  *
296  * Note that the assignment completely changes the %multiset and
297  * that the resulting %multiset's size is the same as the number
298  * of elements assigned. Old data may be lost.
299  */
300  multiset&
301  operator=(initializer_list<value_type> __l)
302  {
303  this->clear();
304  this->insert(__l.begin(), __l.end());
305  return *this;
306  }
307 #endif
308 
309  // accessors:
310 
311  /// Returns the comparison object.
312  key_compare
313  key_comp() const
314  { return _M_t.key_comp(); }
315  /// Returns the comparison object.
316  value_compare
317  value_comp() const
318  { return _M_t.key_comp(); }
319  /// Returns the memory allocation object.
320  allocator_type
321  get_allocator() const _GLIBCXX_NOEXCEPT
322  { return allocator_type(_M_t.get_allocator()); }
323 
324  /**
325  * Returns a read-only (constant) iterator that points to the first
326  * element in the %multiset. Iteration is done in ascending order
327  * according to the keys.
328  */
329  iterator
330  begin() const _GLIBCXX_NOEXCEPT
331  { return _M_t.begin(); }
332 
333  /**
334  * Returns a read-only (constant) iterator that points one past the last
335  * element in the %multiset. Iteration is done in ascending order
336  * according to the keys.
337  */
338  iterator
339  end() const _GLIBCXX_NOEXCEPT
340  { return _M_t.end(); }
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  rbegin() const _GLIBCXX_NOEXCEPT
349  { return _M_t.rbegin(); }
350 
351  /**
352  * Returns a read-only (constant) reverse iterator that points to the
353  * last element in the %multiset. Iteration is done in descending order
354  * according to the keys.
355  */
356  reverse_iterator
357  rend() const _GLIBCXX_NOEXCEPT
358  { return _M_t.rend(); }
359 
360 #if __cplusplus >= 201103L
361  /**
362  * Returns a read-only (constant) iterator that points to the first
363  * element in the %multiset. Iteration is done in ascending order
364  * according to the keys.
365  */
366  iterator
367  cbegin() const noexcept
368  { return _M_t.begin(); }
369 
370  /**
371  * Returns a read-only (constant) iterator that points one past the last
372  * element in the %multiset. Iteration is done in ascending order
373  * according to the keys.
374  */
375  iterator
376  cend() const noexcept
377  { return _M_t.end(); }
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  crbegin() const noexcept
386  { return _M_t.rbegin(); }
387 
388  /**
389  * Returns a read-only (constant) reverse iterator that points to the
390  * last element in the %multiset. Iteration is done in descending order
391  * according to the keys.
392  */
393  reverse_iterator
394  crend() const noexcept
395  { return _M_t.rend(); }
396 #endif
397 
398  /// Returns true if the %set is empty.
399  bool
400  empty() const _GLIBCXX_NOEXCEPT
401  { return _M_t.empty(); }
402 
403  /// Returns the size of the %set.
404  size_type
405  size() const _GLIBCXX_NOEXCEPT
406  { return _M_t.size(); }
407 
408  /// Returns the maximum size of the %set.
409  size_type
410  max_size() const _GLIBCXX_NOEXCEPT
411  { return _M_t.max_size(); }
412 
413  /**
414  * @brief Swaps data with another %multiset.
415  * @param __x A %multiset of the same element and allocator types.
416  *
417  * This exchanges the elements between two multisets in constant time.
418  * (It is only swapping a pointer, an integer, and an instance of the @c
419  * Compare type (which itself is often stateless and empty), so it should
420  * be quite fast.)
421  * Note that the global std::swap() function is specialized such that
422  * std::swap(s1,s2) will feed to this function.
423  */
424  void
426 #if __cplusplus >= 201103L
427  noexcept(_Alloc_traits::_S_nothrow_swap())
428 #endif
429  { _M_t.swap(__x._M_t); }
430 
431  // insert/erase
432 #if __cplusplus >= 201103L
433  /**
434  * @brief Builds and inserts an element into the %multiset.
435  * @param __args Arguments used to generate the element instance to be
436  * inserted.
437  * @return An iterator that points to the inserted element.
438  *
439  * This function inserts an element into the %multiset. Contrary
440  * to a std::set the %multiset does not rely on unique keys and thus
441  * multiple copies of the same element can be inserted.
442  *
443  * Insertion requires logarithmic time.
444  */
445  template<typename... _Args>
446  iterator
447  emplace(_Args&&... __args)
448  { return _M_t._M_emplace_equal(std::forward<_Args>(__args)...); }
449 
450  /**
451  * @brief Builds and inserts an element into the %multiset.
452  * @param __pos An iterator that serves as a hint as to where the
453  * element should be inserted.
454  * @param __args Arguments used to generate the element instance to be
455  * inserted.
456  * @return An iterator that points to the inserted element.
457  *
458  * This function inserts an element into the %multiset. Contrary
459  * to a std::set the %multiset does not rely on unique keys and thus
460  * multiple copies of the same element can be inserted.
461  *
462  * Note that the first parameter is only a hint and can potentially
463  * improve the performance of the insertion process. A bad hint would
464  * cause no gains in efficiency.
465  *
466  * See http://gcc.gnu.org/onlinedocs/libstdc++/manual/bk01pt07ch17.html
467  * for more on @a hinting.
468  *
469  * Insertion requires logarithmic time (if the hint is not taken).
470  */
471  template<typename... _Args>
472  iterator
473  emplace_hint(const_iterator __pos, _Args&&... __args)
474  {
475  return _M_t._M_emplace_hint_equal(__pos,
476  std::forward<_Args>(__args)...);
477  }
478 #endif
479 
480  /**
481  * @brief Inserts an element into the %multiset.
482  * @param __x Element to be inserted.
483  * @return An iterator that points to the inserted element.
484  *
485  * This function inserts an element into the %multiset. Contrary
486  * to a std::set the %multiset does not rely on unique keys and thus
487  * multiple copies of the same element can be inserted.
488  *
489  * Insertion requires logarithmic time.
490  */
491  iterator
492  insert(const value_type& __x)
493  { return _M_t._M_insert_equal(__x); }
494 
495 #if __cplusplus >= 201103L
496  iterator
497  insert(value_type&& __x)
498  { return _M_t._M_insert_equal(std::move(__x)); }
499 #endif
500 
501  /**
502  * @brief Inserts an element into the %multiset.
503  * @param __position An iterator that serves as a hint as to where the
504  * element should be inserted.
505  * @param __x Element to be inserted.
506  * @return An iterator that points to the inserted element.
507  *
508  * This function inserts an element into the %multiset. Contrary
509  * to a std::set the %multiset does not rely on unique keys and thus
510  * multiple copies of the same element can be inserted.
511  *
512  * Note that the first parameter is only a hint and can potentially
513  * improve the performance of the insertion process. A bad hint would
514  * cause no gains in efficiency.
515  *
516  * See http://gcc.gnu.org/onlinedocs/libstdc++/manual/bk01pt07ch17.html
517  * for more on @a hinting.
518  *
519  * Insertion requires logarithmic time (if the hint is not taken).
520  */
521  iterator
522  insert(const_iterator __position, const value_type& __x)
523  { return _M_t._M_insert_equal_(__position, __x); }
524 
525 #if __cplusplus >= 201103L
526  iterator
527  insert(const_iterator __position, value_type&& __x)
528  { return _M_t._M_insert_equal_(__position, std::move(__x)); }
529 #endif
530 
531  /**
532  * @brief A template function that tries to insert a range of elements.
533  * @param __first Iterator pointing to the start of the range to be
534  * inserted.
535  * @param __last Iterator pointing to the end of the range.
536  *
537  * Complexity similar to that of the range constructor.
538  */
539  template<typename _InputIterator>
540  void
541  insert(_InputIterator __first, _InputIterator __last)
542  { _M_t._M_insert_equal(__first, __last); }
543 
544 #if __cplusplus >= 201103L
545  /**
546  * @brief Attempts to insert a list of elements into the %multiset.
547  * @param __l A std::initializer_list<value_type> of elements
548  * to be inserted.
549  *
550  * Complexity similar to that of the range constructor.
551  */
552  void
553  insert(initializer_list<value_type> __l)
554  { this->insert(__l.begin(), __l.end()); }
555 #endif
556 
557 #if __cplusplus >= 201103L
558  // _GLIBCXX_RESOLVE_LIB_DEFECTS
559  // DR 130. Associative erase should return an iterator.
560  /**
561  * @brief Erases an element from a %multiset.
562  * @param __position An iterator pointing to the element to be erased.
563  * @return An iterator pointing to the element immediately following
564  * @a position prior to the element being erased. If no such
565  * element exists, end() is returned.
566  *
567  * This function erases an element, pointed to by the given iterator,
568  * from a %multiset. Note that this function only erases the element,
569  * and that if the element is itself a pointer, the pointed-to memory is
570  * not touched in any way. Managing the pointer is the user's
571  * responsibility.
572  */
573  _GLIBCXX_ABI_TAG_CXX11
574  iterator
575  erase(const_iterator __position)
576  { return _M_t.erase(__position); }
577 #else
578  /**
579  * @brief Erases an element from a %multiset.
580  * @param __position An iterator pointing to the element to be erased.
581  *
582  * This function erases an element, pointed to by the given iterator,
583  * from a %multiset. Note that this function only erases the element,
584  * and that if the element is itself a pointer, the pointed-to memory is
585  * not touched in any way. Managing the pointer is the user's
586  * responsibility.
587  */
588  void
589  erase(iterator __position)
590  { _M_t.erase(__position); }
591 #endif
592 
593  /**
594  * @brief Erases elements according to the provided key.
595  * @param __x Key of element to be erased.
596  * @return The number of elements erased.
597  *
598  * This function erases all elements located by the given key from a
599  * %multiset.
600  * Note that this function only erases the element, and that if
601  * the element is itself a pointer, the pointed-to memory is not touched
602  * in any way. Managing the pointer is the user's responsibility.
603  */
604  size_type
605  erase(const key_type& __x)
606  { return _M_t.erase(__x); }
607 
608 #if __cplusplus >= 201103L
609  // _GLIBCXX_RESOLVE_LIB_DEFECTS
610  // DR 130. Associative erase should return an iterator.
611  /**
612  * @brief Erases a [first,last) range of elements from a %multiset.
613  * @param __first Iterator pointing to the start of the range to be
614  * erased.
615  * @param __last Iterator pointing to the end of the range to
616  * be erased.
617  * @return The iterator @a last.
618  *
619  * This function erases a sequence of elements from a %multiset.
620  * Note that this function only erases the elements, and that if
621  * the elements themselves are pointers, the pointed-to memory is not
622  * touched in any way. Managing the pointer is the user's
623  * responsibility.
624  */
625  _GLIBCXX_ABI_TAG_CXX11
626  iterator
627  erase(const_iterator __first, const_iterator __last)
628  { return _M_t.erase(__first, __last); }
629 #else
630  /**
631  * @brief Erases a [first,last) range of elements from a %multiset.
632  * @param first Iterator pointing to the start of the range to be
633  * erased.
634  * @param last Iterator pointing to the end of the range to be erased.
635  *
636  * This function erases a sequence of elements from a %multiset.
637  * Note that this function only erases the elements, and that if
638  * the elements themselves are pointers, the pointed-to memory is not
639  * touched in any way. Managing the pointer is the user's
640  * responsibility.
641  */
642  void
643  erase(iterator __first, iterator __last)
644  { _M_t.erase(__first, __last); }
645 #endif
646 
647  /**
648  * Erases all elements in a %multiset. Note that this function only
649  * erases the elements, and that if the elements themselves are pointers,
650  * the pointed-to memory is not touched in any way. Managing the pointer
651  * is the user's responsibility.
652  */
653  void
654  clear() _GLIBCXX_NOEXCEPT
655  { _M_t.clear(); }
656 
657  // multiset operations:
658 
659  /**
660  * @brief Finds the number of elements with given key.
661  * @param __x Key of elements to be located.
662  * @return Number of elements with specified key.
663  */
664  size_type
665  count(const key_type& __x) const
666  { return _M_t.count(__x); }
667 
668  // _GLIBCXX_RESOLVE_LIB_DEFECTS
669  // 214. set::find() missing const overload
670  //@{
671  /**
672  * @brief Tries to locate an element in a %set.
673  * @param __x Element to be located.
674  * @return Iterator pointing to sought-after element, or end() if not
675  * found.
676  *
677  * This function takes a key and tries to locate the element with which
678  * the key matches. If successful the function returns an iterator
679  * pointing to the sought after element. If unsuccessful it returns the
680  * past-the-end ( @c end() ) iterator.
681  */
682  iterator
683  find(const key_type& __x)
684  { return _M_t.find(__x); }
685 
686  const_iterator
687  find(const key_type& __x) const
688  { return _M_t.find(__x); }
689  //@}
690 
691  //@{
692  /**
693  * @brief Finds the beginning of a subsequence matching given key.
694  * @param __x Key to be located.
695  * @return Iterator pointing to first element equal to or greater
696  * than key, or end().
697  *
698  * This function returns the first element of a subsequence of elements
699  * that matches the given key. If unsuccessful it returns an iterator
700  * pointing to the first element that has a greater value than given key
701  * or end() if no such element exists.
702  */
703  iterator
704  lower_bound(const key_type& __x)
705  { return _M_t.lower_bound(__x); }
706 
707  const_iterator
708  lower_bound(const key_type& __x) const
709  { return _M_t.lower_bound(__x); }
710  //@}
711 
712  //@{
713  /**
714  * @brief Finds the end of a subsequence matching given key.
715  * @param __x Key to be located.
716  * @return Iterator pointing to the first element
717  * greater than key, or end().
718  */
719  iterator
720  upper_bound(const key_type& __x)
721  { return _M_t.upper_bound(__x); }
722 
723  const_iterator
724  upper_bound(const key_type& __x) const
725  { return _M_t.upper_bound(__x); }
726  //@}
727 
728  //@{
729  /**
730  * @brief Finds a subsequence matching given key.
731  * @param __x Key to be located.
732  * @return Pair of iterators that possibly points to the subsequence
733  * matching given key.
734  *
735  * This function is equivalent to
736  * @code
737  * std::make_pair(c.lower_bound(val),
738  * c.upper_bound(val))
739  * @endcode
740  * (but is faster than making the calls separately).
741  *
742  * This function probably only makes sense for multisets.
743  */
745  equal_range(const key_type& __x)
746  { return _M_t.equal_range(__x); }
747 
749  equal_range(const key_type& __x) const
750  { return _M_t.equal_range(__x); }
751  //@}
752 
753  template<typename _K1, typename _C1, typename _A1>
754  friend bool
755  operator==(const multiset<_K1, _C1, _A1>&,
756  const multiset<_K1, _C1, _A1>&);
757 
758  template<typename _K1, typename _C1, typename _A1>
759  friend bool
760  operator< (const multiset<_K1, _C1, _A1>&,
761  const multiset<_K1, _C1, _A1>&);
762  };
763 
764  /**
765  * @brief Multiset equality comparison.
766  * @param __x A %multiset.
767  * @param __y A %multiset of the same type as @a __x.
768  * @return True iff the size and elements of the multisets are equal.
769  *
770  * This is an equivalence relation. It is linear in the size of the
771  * multisets.
772  * Multisets are considered equivalent if their sizes are equal, and if
773  * corresponding elements compare equal.
774  */
775  template<typename _Key, typename _Compare, typename _Alloc>
776  inline bool
777  operator==(const multiset<_Key, _Compare, _Alloc>& __x,
779  { return __x._M_t == __y._M_t; }
780 
781  /**
782  * @brief Multiset ordering relation.
783  * @param __x A %multiset.
784  * @param __y A %multiset of the same type as @a __x.
785  * @return True iff @a __x is lexicographically less than @a __y.
786  *
787  * This is a total ordering relation. It is linear in the size of the
788  * sets. The elements must be comparable with @c <.
789  *
790  * See std::lexicographical_compare() for how the determination is made.
791  */
792  template<typename _Key, typename _Compare, typename _Alloc>
793  inline bool
794  operator<(const multiset<_Key, _Compare, _Alloc>& __x,
796  { return __x._M_t < __y._M_t; }
797 
798  /// Returns !(x == y).
799  template<typename _Key, typename _Compare, typename _Alloc>
800  inline bool
801  operator!=(const multiset<_Key, _Compare, _Alloc>& __x,
803  { return !(__x == __y); }
804 
805  /// Returns y < x.
806  template<typename _Key, typename _Compare, typename _Alloc>
807  inline bool
810  { return __y < __x; }
811 
812  /// Returns !(y < x)
813  template<typename _Key, typename _Compare, typename _Alloc>
814  inline bool
815  operator<=(const multiset<_Key, _Compare, _Alloc>& __x,
817  { return !(__y < __x); }
818 
819  /// Returns !(x < y)
820  template<typename _Key, typename _Compare, typename _Alloc>
821  inline bool
824  { return !(__x < __y); }
825 
826  /// See std::multiset::swap().
827  template<typename _Key, typename _Compare, typename _Alloc>
828  inline void
831  { __x.swap(__y); }
832 
833 _GLIBCXX_END_NAMESPACE_CONTAINER
834 } // namespace std
835 
836 #endif /* _STL_MULTISET_H */
multiset(_InputIterator __first, _InputIterator __last)
Builds a multiset from a range.
Definition: stl_multiset.h:163
_GLIBCXX_ABI_TAG_CXX11 iterator erase(const_iterator __position)
Erases an element from a multiset.
Definition: stl_multiset.h:575
multiset(initializer_list< value_type > __l, const allocator_type &__a)
Allocator-extended initialier-list constructor.
Definition: stl_multiset.h:239
iterator insert(const_iterator __position, const value_type &__x)
Inserts an element into the multiset.
Definition: stl_multiset.h:522
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
Definition: move.h:101
reverse_iterator crend() const noexcept
Definition: stl_multiset.h:394
std::pair< const_iterator, const_iterator > equal_range(const key_type &__x) const
Finds a subsequence matching given key.
Definition: stl_multiset.h:749
reverse_iterator crbegin() const noexcept
Definition: stl_multiset.h:385
iterator cend() const noexcept
Definition: stl_multiset.h:376
reverse_iterator rend() const noexcept
Definition: stl_multiset.h:357
multiset(const multiset &__x)
Multiset copy constructor.
Definition: stl_multiset.h:192
std::pair< iterator, iterator > equal_range(const key_type &__x)
Finds a subsequence matching given key.
Definition: stl_multiset.h:745
Uniform interface to C++98 and C++0x allocators.
void clear() noexcept
Definition: stl_multiset.h:654
iterator end() const noexcept
Definition: stl_multiset.h:339
multiset(initializer_list< value_type > __l, const _Compare &__comp=_Compare(), const allocator_type &__a=allocator_type())
Builds a multiset from an initializer_list.
Definition: stl_multiset.h:217
multiset & operator=(multiset &&__x) noexcept(_Alloc_traits::_S_nothrow_move())
Multiset move assignment operator.
Definition: stl_multiset.h:275
void insert(_InputIterator __first, _InputIterator __last)
A template function that tries to insert a range of elements.
Definition: stl_multiset.h:541
size_type max_size() const noexcept
Returns the maximum size of the set.
Definition: stl_multiset.h:410
allocator_type get_allocator() const noexcept
Returns the memory allocation object.
Definition: stl_multiset.h:321
iterator lower_bound(const key_type &__x)
Finds the beginning of a subsequence matching given key.
Definition: stl_multiset.h:704
iterator insert(const value_type &__x)
Inserts an element into the multiset.
Definition: stl_multiset.h:492
size_type size() const noexcept
Returns the size of the set.
Definition: stl_multiset.h:405
key_compare key_comp() const
Returns the comparison object.
Definition: stl_multiset.h:313
multiset(_InputIterator __first, _InputIterator __last, const allocator_type &__a)
Allocator-extended range constructor.
Definition: stl_multiset.h:245
ISO C++ entities toplevel namespace is std.
iterator emplace(_Args &&...__args)
Builds and inserts an element into the multiset.
Definition: stl_multiset.h:447
multiset & operator=(const multiset &__x)
Multiset assignment operator.
Definition: stl_multiset.h:259
const_iterator upper_bound(const key_type &__x) const
Finds the end of a subsequence matching given key.
Definition: stl_multiset.h:724
reverse_iterator rbegin() const noexcept
Definition: stl_multiset.h:348
multiset(const allocator_type &__a)
Allocator-extended default constructor.
Definition: stl_multiset.h:225
bool empty() const noexcept
Returns true if the set is empty.
Definition: stl_multiset.h:400
multiset(multiset &&__x) noexcept(is_nothrow_copy_constructible< _Compare >::value)
Multiset move constructor.
Definition: stl_multiset.h:203
_GLIBCXX_ABI_TAG_CXX11 iterator erase(const_iterator __first, const_iterator __last)
Erases a [first,last) range of elements from a multiset.
Definition: stl_multiset.h:627
const_iterator find(const key_type &__x) const
Tries to locate an element in a set.
Definition: stl_multiset.h:687
multiset(_InputIterator __first, _InputIterator __last, const _Compare &__comp, const allocator_type &__a=allocator_type())
Builds a multiset from a range.
Definition: stl_multiset.h:179
bool operator>=(const basic_string< _CharT, _Traits, _Alloc > &__lhs, const basic_string< _CharT, _Traits, _Alloc > &__rhs)
Test if string doesn't precede string.
iterator cbegin() const noexcept
Definition: stl_multiset.h:367
iterator emplace_hint(const_iterator __pos, _Args &&...__args)
Builds and inserts an element into the multiset.
Definition: stl_multiset.h:473
multiset(const _Compare &__comp, const allocator_type &__a=allocator_type())
Creates a multiset with no elements.
Definition: stl_multiset.h:149
const_iterator lower_bound(const key_type &__x) const
Finds the beginning of a subsequence matching given key.
Definition: stl_multiset.h:708
A standard container made up of elements, which can be retrieved in logarithmic time.
Definition: stl_multiset.h:92
size_type erase(const key_type &__x)
Erases elements according to the provided key.
Definition: stl_multiset.h:605
value_compare value_comp() const
Returns the comparison object.
Definition: stl_multiset.h:317
bool operator>(const basic_string< _CharT, _Traits, _Alloc > &__lhs, const basic_string< _CharT, _Traits, _Alloc > &__rhs)
Test if string follows string.
size_type count(const key_type &__x) const
Finds the number of elements with given key.
Definition: stl_multiset.h:665
iterator find(const key_type &__x)
Tries to locate an element in a set.
Definition: stl_multiset.h:683
void insert(initializer_list< value_type > __l)
Attempts to insert a list of elements into the multiset.
Definition: stl_multiset.h:553
Struct holding two objects of arbitrary type.
Definition: stl_pair.h:96
multiset & operator=(initializer_list< value_type > __l)
Multiset list assignment operator.
Definition: stl_multiset.h:301
void swap(_Tp &, _Tp &) noexcept(__and_< is_nothrow_move_constructible< _Tp >, is_nothrow_move_assignable< _Tp >>::value)
Swaps two values.
Definition: move.h:166
iterator upper_bound(const key_type &__x)
Finds the end of a subsequence matching given key.
Definition: stl_multiset.h:720
iterator begin() const noexcept
Definition: stl_multiset.h:330
multiset(multiset &&__m, const allocator_type &__a) noexcept(is_nothrow_copy_constructible< _Compare >::value &&_Alloc_traits::_S_always_equal())
Allocator-extended move constructor.
Definition: stl_multiset.h:233
multiset(const multiset &__m, const allocator_type &__a)
Allocator-extended copy constructor.
Definition: stl_multiset.h:229
void swap(multiset &__x) noexcept(_Alloc_traits::_S_nothrow_swap())
Swaps data with another multiset.
Definition: stl_multiset.h:425
multiset()
Default constructor creates no elements.
Definition: stl_multiset.h:140