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  : _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  /// 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
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  /**
641  * @brief Finds the number of elements with given key.
642  * @param __x Key of elements to be located.
643  * @return Number of elements with specified key.
644  */
645  size_type
646  count(const key_type& __x) const
647  { return _M_t.count(__x); }
648 
649 #if __cplusplus > 201103L
650  template<typename _Kt>
651  auto
652  count(const _Kt& __x) const -> decltype(_M_t._M_count_tr(__x))
653  { return _M_t._M_count_tr(__x); }
654 #endif
655  //@}
656 
657  // _GLIBCXX_RESOLVE_LIB_DEFECTS
658  // 214. set::find() missing const overload
659  //@{
660  /**
661  * @brief Tries to locate an element in a %set.
662  * @param __x Element to be located.
663  * @return Iterator pointing to sought-after element, or end() if not
664  * found.
665  *
666  * This function takes a key and tries to locate the element with which
667  * the key matches. If successful the function returns an iterator
668  * pointing to the sought after element. If unsuccessful it returns the
669  * past-the-end ( @c end() ) iterator.
670  */
671  iterator
672  find(const key_type& __x)
673  { return _M_t.find(__x); }
674 
675  const_iterator
676  find(const key_type& __x) const
677  { return _M_t.find(__x); }
678 
679 #if __cplusplus > 201103L
680  template<typename _Kt>
681  auto
682  find(const _Kt& __x) -> decltype(_M_t._M_find_tr(__x))
683  { return _M_t._M_find_tr(__x); }
684 
685  template<typename _Kt>
686  auto
687  find(const _Kt& __x) const -> decltype(_M_t._M_find_tr(__x))
688  { return _M_t._M_find_tr(__x); }
689 #endif
690  //@}
691 
692  //@{
693  /**
694  * @brief Finds the beginning of a subsequence matching given key.
695  * @param __x Key to be located.
696  * @return Iterator pointing to first element equal to or greater
697  * than key, or end().
698  *
699  * This function returns the first element of a subsequence of elements
700  * that matches the given key. If unsuccessful it returns an iterator
701  * pointing to the first element that has a greater value than given key
702  * or end() if no such element exists.
703  */
704  iterator
705  lower_bound(const key_type& __x)
706  { return _M_t.lower_bound(__x); }
707 
708  const_iterator
709  lower_bound(const key_type& __x) const
710  { return _M_t.lower_bound(__x); }
711 
712 #if __cplusplus > 201103L
713  template<typename _Kt>
714  auto
715  lower_bound(const _Kt& __x)
716  -> decltype(_M_t._M_lower_bound_tr(__x))
717  { return _M_t._M_lower_bound_tr(__x); }
718 
719  template<typename _Kt>
720  auto
721  lower_bound(const _Kt& __x) const
722  -> decltype(_M_t._M_lower_bound_tr(__x))
723  { return _M_t._M_lower_bound_tr(__x); }
724 #endif
725  //@}
726 
727  //@{
728  /**
729  * @brief Finds the end of a subsequence matching given key.
730  * @param __x Key to be located.
731  * @return Iterator pointing to the first element
732  * greater than key, or end().
733  */
734  iterator
735  upper_bound(const key_type& __x)
736  { return _M_t.upper_bound(__x); }
737 
738  const_iterator
739  upper_bound(const key_type& __x) const
740  { return _M_t.upper_bound(__x); }
741 
742 #if __cplusplus > 201103L
743  template<typename _Kt>
744  auto
745  upper_bound(const _Kt& __x)
746  -> decltype(_M_t._M_upper_bound_tr(__x))
747  { return _M_t._M_upper_bound_tr(__x); }
748 
749  template<typename _Kt>
750  auto
751  upper_bound(const _Kt& __x) const
752  -> decltype(_M_t._M_upper_bound_tr(__x))
753  { return _M_t._M_upper_bound_tr(__x); }
754 #endif
755  //@}
756 
757  //@{
758  /**
759  * @brief Finds a subsequence matching given key.
760  * @param __x Key to be located.
761  * @return Pair of iterators that possibly points to the subsequence
762  * matching given key.
763  *
764  * This function is equivalent to
765  * @code
766  * std::make_pair(c.lower_bound(val),
767  * c.upper_bound(val))
768  * @endcode
769  * (but is faster than making the calls separately).
770  *
771  * This function probably only makes sense for multisets.
772  */
774  equal_range(const key_type& __x)
775  { return _M_t.equal_range(__x); }
776 
778  equal_range(const key_type& __x) const
779  { return _M_t.equal_range(__x); }
780 
781 #if __cplusplus > 201103L
782  template<typename _Kt>
783  auto
784  equal_range(const _Kt& __x)
785  -> decltype(_M_t._M_equal_range_tr(__x))
786  { return _M_t._M_equal_range_tr(__x); }
787 
788  template<typename _Kt>
789  auto
790  equal_range(const _Kt& __x) const
791  -> decltype(_M_t._M_equal_range_tr(__x))
792  { return _M_t._M_equal_range_tr(__x); }
793 #endif
794  //@}
795 
796  template<typename _K1, typename _C1, typename _A1>
797  friend bool
798  operator==(const multiset<_K1, _C1, _A1>&,
799  const multiset<_K1, _C1, _A1>&);
800 
801  template<typename _K1, typename _C1, typename _A1>
802  friend bool
803  operator< (const multiset<_K1, _C1, _A1>&,
804  const multiset<_K1, _C1, _A1>&);
805  };
806 
807  /**
808  * @brief Multiset equality comparison.
809  * @param __x A %multiset.
810  * @param __y A %multiset of the same type as @a __x.
811  * @return True iff the size and elements of the multisets are equal.
812  *
813  * This is an equivalence relation. It is linear in the size of the
814  * multisets.
815  * Multisets are considered equivalent if their sizes are equal, and if
816  * corresponding elements compare equal.
817  */
818  template<typename _Key, typename _Compare, typename _Alloc>
819  inline bool
820  operator==(const multiset<_Key, _Compare, _Alloc>& __x,
822  { return __x._M_t == __y._M_t; }
823 
824  /**
825  * @brief Multiset ordering relation.
826  * @param __x A %multiset.
827  * @param __y A %multiset of the same type as @a __x.
828  * @return True iff @a __x is lexicographically less than @a __y.
829  *
830  * This is a total ordering relation. It is linear in the size of the
831  * sets. The elements must be comparable with @c <.
832  *
833  * See std::lexicographical_compare() for how the determination is made.
834  */
835  template<typename _Key, typename _Compare, typename _Alloc>
836  inline bool
837  operator<(const multiset<_Key, _Compare, _Alloc>& __x,
839  { return __x._M_t < __y._M_t; }
840 
841  /// Returns !(x == y).
842  template<typename _Key, typename _Compare, typename _Alloc>
843  inline bool
844  operator!=(const multiset<_Key, _Compare, _Alloc>& __x,
846  { return !(__x == __y); }
847 
848  /// Returns y < x.
849  template<typename _Key, typename _Compare, typename _Alloc>
850  inline bool
853  { return __y < __x; }
854 
855  /// Returns !(y < x)
856  template<typename _Key, typename _Compare, typename _Alloc>
857  inline bool
858  operator<=(const multiset<_Key, _Compare, _Alloc>& __x,
860  { return !(__y < __x); }
861 
862  /// Returns !(x < y)
863  template<typename _Key, typename _Compare, typename _Alloc>
864  inline bool
867  { return !(__x < __y); }
868 
869  /// See std::multiset::swap().
870  template<typename _Key, typename _Compare, typename _Alloc>
871  inline void
874  { __x.swap(__y); }
875 
876 _GLIBCXX_END_NAMESPACE_CONTAINER
877 } // namespace std
878 
879 #endif /* _STL_MULTISET_H */
void swap(_Tp &, _Tp &) noexcept(__and_< is_nothrow_move_constructible< _Tp >, is_nothrow_move_assignable< _Tp >>::value)
Swaps two values.
Definition: move.h:176
value_compare value_comp() const
Returns the comparison object.
Definition: stl_multiset.h:297
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(_InputIterator __first, _InputIterator __last, const allocator_type &__a)
Allocator-extended range constructor.
Definition: stl_multiset.h:245
iterator cbegin() const noexcept
Definition: stl_multiset.h:347
multiset(const allocator_type &__a)
Allocator-extended default constructor.
Definition: stl_multiset.h:225
iterator upper_bound(const key_type &__x)
Finds the end of a subsequence matching given key.
Definition: stl_multiset.h:735
size_type erase(const key_type &__x)
Erases elements according to the provided key.
Definition: stl_multiset.h:585
bool empty() const noexcept
Returns true if the set is empty.
Definition: stl_multiset.h:380
multiset & operator=(initializer_list< value_type > __l)
Multiset list assignment operator.
Definition: stl_multiset.h:282
iterator emplace_hint(const_iterator __pos, _Args &&...__args)
Builds and inserts an element into the multiset.
Definition: stl_multiset.h:453
void insert(_InputIterator __first, _InputIterator __last)
A template function that tries to insert a range of elements.
Definition: stl_multiset.h:521
Uniform interface to C++98 and C++0x allocators.
multiset(const multiset &__m, const allocator_type &__a)
Allocator-extended copy constructor.
Definition: stl_multiset.h:229
bool operator>=(const basic_string< _CharT, _Traits, _Alloc > &__lhs, const basic_string< _CharT, _Traits, _Alloc > &__rhs)
Test if string doesn't precede string.
multiset & operator=(const multiset &__x)
Multiset assignment operator.
Definition: stl_multiset.h:259
multiset(_InputIterator __first, _InputIterator __last)
Builds a multiset from a range.
Definition: stl_multiset.h:163
iterator end() const noexcept
Definition: stl_multiset.h:319
iterator lower_bound(const key_type &__x)
Finds the beginning of a subsequence matching given key.
Definition: stl_multiset.h:705
multiset()
Default constructor creates no elements.
Definition: stl_multiset.h:140
key_compare key_comp() const
Returns the comparison object.
Definition: stl_multiset.h:293
iterator find(const key_type &__x)
Tries to locate an element in a set.
Definition: stl_multiset.h:672
allocator_type get_allocator() const noexcept
Returns the memory allocation object.
Definition: stl_multiset.h:301
iterator cend() const noexcept
Definition: stl_multiset.h:356
multiset(initializer_list< value_type > __l, const allocator_type &__a)
Allocator-extended initialier-list constructor.
Definition: stl_multiset.h:239
multiset(const multiset &__x)
Multiset copy constructor.
Definition: stl_multiset.h:192
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 _Compare &__comp, const allocator_type &__a=allocator_type())
Creates a multiset with no elements.
Definition: stl_multiset.h:149
reverse_iterator rbegin() const noexcept
Definition: stl_multiset.h:328
bool operator>(const basic_string< _CharT, _Traits, _Alloc > &__lhs, const basic_string< _CharT, _Traits, _Alloc > &__rhs)
Test if string follows string.
iterator begin() const noexcept
Definition: stl_multiset.h:310
const_iterator upper_bound(const key_type &__x) const
Finds the end of a subsequence matching given key.
Definition: stl_multiset.h:739
size_type max_size() const noexcept
Returns the maximum size of the set.
Definition: stl_multiset.h:390
size_type size() const noexcept
Returns the size of the set.
Definition: stl_multiset.h:385
_GLIBCXX_ABI_TAG_CXX11 iterator erase(const_iterator __position)
Erases an element from a multiset.
Definition: stl_multiset.h:555
iterator insert(const value_type &__x)
Inserts an element into the multiset.
Definition: stl_multiset.h:472
std::pair< const_iterator, const_iterator > equal_range(const key_type &__x) const
Finds a subsequence matching given key.
Definition: stl_multiset.h:778
A standard container made up of elements, which can be retrieved in logarithmic time.
Definition: stl_multiset.h:92
void clear() noexcept
Definition: stl_multiset.h:634
iterator insert(const_iterator __position, const value_type &__x)
Inserts an element into the multiset.
Definition: stl_multiset.h:502
void swap(multiset &__x) noexcept(_Alloc_traits::_S_nothrow_swap())
Swaps data with another multiset.
Definition: stl_multiset.h:405
void insert(initializer_list< value_type > __l)
Attempts to insert a list of elements into the multiset.
Definition: stl_multiset.h:533
reverse_iterator rend() const noexcept
Definition: stl_multiset.h:337
multiset(multiset &&__x) noexcept(is_nothrow_copy_constructible< _Compare >::value)
Multiset move constructor.
Definition: stl_multiset.h:203
reverse_iterator crend() const noexcept
Definition: stl_multiset.h:374
const_iterator lower_bound(const key_type &__x) const
Finds the beginning of a subsequence matching given key.
Definition: stl_multiset.h:709
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
iterator emplace(_Args &&...__args)
Builds and inserts an element into the multiset.
Definition: stl_multiset.h:427
Struct holding two objects of arbitrary type.
Definition: stl_pair.h:96
size_type count(const key_type &__x) const
Finds the number of elements with given key.
Definition: stl_multiset.h:646
const_iterator find(const key_type &__x) const
Tries to locate an element in a set.
Definition: stl_multiset.h:676
_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:607
std::pair< iterator, iterator > equal_range(const key_type &__x)
Finds a subsequence matching given key.
Definition: stl_multiset.h:774
reverse_iterator crbegin() const noexcept
Definition: stl_multiset.h:365
ISO C++ entities toplevel namespace is std.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
Definition: move.h:101