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