A standard container made up of elements, which can be retrieved in logarithmic time.
- Template Parameters
-
_Key | Type of key objects. |
_Compare | Comparison function object type, defaults to less<_Key>. |
_Alloc | Allocator type, defaults to allocator<_Key>. |
Meets the requirements of a container, a reversible container, and an associative container (using equivalent keys). For a multiset<Key>
the key_type and value_type are Key.
Multisets support bidirectional iterators.
The private tree data is declared exactly the same way for set and multiset; the distinction is made entirely in how the tree functions are called (*_unique versus *_equal, same as the standard).
This turns a red-black tree into a [multi]set.
The actual tree structure.
Default constructor creates no elements.
Creates a multiset with no elements.
- Parameters
-
__comp | Comparator to use. |
__a | An allocator object. |
Builds a multiset from a range.
- Parameters
-
__first | An input iterator. |
__last | An input iterator. |
Create a multiset consisting of copies of the elements from [first,last). This is linear in N if the range is already sorted, and NlogN otherwise (where N is distance(__first,__last)).
Builds a multiset from a range.
- Parameters
-
__first | An input iterator. |
__last | An input iterator. |
__comp | A comparison functor. |
__a | An allocator object. |
Create a multiset consisting of copies of the elements from [__first,__last). This is linear in N if the range is already sorted, and NlogN otherwise (where N is distance(__first,__last)).
Multiset copy constructor.
- Parameters
-
__x | A multiset of identical element and allocator types. |
The newly-created multiset uses a copy of the allocation object used by __x.
Multiset assignment operator.
- Parameters
-
__x | A multiset of identical element and allocator types. |
All the elements of __x are copied, but unlike the copy constructor, the allocator object is not copied.
Returns the comparison object.
Returns the comparison object.
Returns the memory allocation object.
Returns a read-only (constant) iterator that points to the first element in the multiset. Iteration is done in ascending order according to the keys.
Returns a read-only (constant) iterator that points one past the last element in the multiset. Iteration is done in ascending order according to the keys.
Returns a read-only (constant) reverse iterator that points to the last element in the multiset. Iteration is done in descending order according to the keys.
Returns a read-only (constant) reverse iterator that points to the last element in the multiset. Iteration is done in descending order according to the keys.
Returns true if the set is empty.
Returns the size of the set.
Returns the maximum size of the set.
Swaps data with another multiset.
- Parameters
-
__x | A multiset of the same element and allocator types. |
This exchanges the elements between two multisets in constant time. (It is only swapping a pointer, an integer, and an instance of the Compare
type (which itself is often stateless and empty), so it should be quite fast.) Note that the global std::swap() function is specialized such that std::swap(s1,s2) will feed to this function.
Inserts an element into the multiset.
- Parameters
-
__x | Element to be inserted. |
- Returns
- An iterator that points to the inserted element.
This function inserts an element into the multiset. Contrary to a std::set the multiset does not rely on unique keys and thus multiple copies of the same element can be inserted.
Insertion requires logarithmic time.
Inserts an element into the multiset.
- Parameters
-
__position | An iterator that serves as a hint as to where the element should be inserted. |
__x | Element to be inserted. |
- Returns
- An iterator that points to the inserted element.
This function inserts an element into the multiset. Contrary to a std::set the multiset does not rely on unique keys and thus multiple copies of the same element can be inserted.
Note that the first parameter is only a hint and can potentially improve the performance of the insertion process. A bad hint would cause no gains in efficiency.
See http://gcc.gnu.org/onlinedocs/libstdc++/manual/bk01pt07ch17.html for more on hinting.
Insertion requires logarithmic time (if the hint is not taken).
A template function that tries to insert a range of elements.
- Parameters
-
__first | Iterator pointing to the start of the range to be inserted. |
__last | Iterator pointing to the end of the range. |
Complexity similar to that of the range constructor.
Erases an element from a multiset.
- Parameters
-
__position | An iterator pointing to the element to be erased. |
This function erases an element, pointed to by the given iterator, from a multiset. Note that this function only erases the element, and that if the element is itself a pointer, the pointed-to memory is not touched in any way. Managing the pointer is the user's responsibility.
Erases elements according to the provided key.
- Parameters
-
__x | Key of element to be erased. |
- Returns
- The number of elements erased.
This function erases all elements located by the given key from a multiset. Note that this function only erases the element, and that if the element is itself a pointer, the pointed-to memory is not touched in any way. Managing the pointer is the user's responsibility.
Erases a [first,last) range of elements from a multiset.
- Parameters
-
first | Iterator pointing to the start of the range to be erased. |
last | Iterator pointing to the end of the range to be erased. |
This function erases a sequence of elements from a multiset. Note that this function only erases the elements, and that if the elements themselves are pointers, the pointed-to memory is not touched in any way. Managing the pointer is the user's responsibility.
Erases all elements in a multiset. Note that this function only erases the elements, and that if the elements themselves are pointers, the pointed-to memory is not touched in any way. Managing the pointer is the user's responsibility.
Finds the number of elements with given key.
- Parameters
-
__x | Key of elements to be located. |
- Returns
- Number of elements with specified key.
Tries to locate an element in a set.
- Parameters
-
__x | Element to be located. |
- Returns
- Iterator pointing to sought-after element, or end() if not found.
This function takes a key and tries to locate the element with which the key matches. If successful the function returns an iterator pointing to the sought after element. If unsuccessful it returns the past-the-end ( end()
) iterator.
Finds the beginning of a subsequence matching given key.
- Parameters
-
- Returns
- Iterator pointing to first element equal to or greater than key, or end().
This function returns the first element of a subsequence of elements that matches the given key. If unsuccessful it returns an iterator pointing to the first element that has a greater value than given key or end() if no such element exists.
Finds the end of a subsequence matching given key.
- Parameters
-
- Returns
- Iterator pointing to the first element greater than key, or end().
Finds a subsequence matching given key.
- Parameters
-
- Returns
- Pair of iterators that possibly points to the subsequence matching given key.
This function is equivalent to
std::make_pair(c.lower_bound(val),
c.upper_bound(val))
(but is faster than making the calls separately).
This function probably only makes sense for multisets.
Multiset equality comparison.
- Parameters
-
__x | A multiset. |
__y | A multiset of the same type as __x. |
- Returns
- True iff the size and elements of the multisets are equal.
This is an equivalence relation. It is linear in the size of the multisets. Multisets are considered equivalent if their sizes are equal, and if corresponding elements compare equal.
Multiset ordering relation.
- Parameters
-
__x | A multiset. |
__y | A multiset of the same type as __x. |
- Returns
- True iff __x is lexicographically less than __y.
This is a total ordering relation. It is linear in the size of the maps. The elements must be comparable with <
.
See std::lexicographical_compare() for how the determination is made.
Returns !(x == y).
Returns y < x.
Returns !(y < x)
Returns !(x < y)
See std::multiset::swap().
66 _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
90 template <
typename _Key,
typename _Compare = std::less<_Key>,
91 typename _Alloc = std::allocator<_Key> >
95 typedef typename _Alloc::value_type _Alloc_value_type;
98 _BinaryFunctionConcept)
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;
111 typedef typename _Alloc::template rebind<_Key>::other _Key_alloc_type;
113 typedef _Rb_tree<key_type, value_type, _Identity<value_type>,
114 key_compare, _Key_alloc_type> _Rep_type;
119 typedef typename _Key_alloc_type::pointer pointer;
120 typedef typename _Key_alloc_type::const_pointer const_pointer;
121 typedef typename _Key_alloc_type::reference reference;
122 typedef typename _Key_alloc_type::const_reference const_reference;
126 typedef typename _Rep_type::const_iterator iterator;
127 typedef typename _Rep_type::const_iterator const_iterator;
128 typedef typename _Rep_type::const_reverse_iterator reverse_iterator;
129 typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator;
130 typedef typename _Rep_type::size_type size_type;
131 typedef typename _Rep_type::difference_type difference_type;
146 multiset(
const _Compare& __comp,
147 const allocator_type& __a = allocator_type())
148 : _M_t(__comp, _Key_alloc_type(__a)) { }
159 template<
typename _InputIterator>
160 multiset(_InputIterator __first, _InputIterator __last)
162 { _M_t._M_insert_equal(__first, __last); }
175 template<
typename _InputIterator>
176 multiset(_InputIterator __first, _InputIterator __last,
177 const _Compare& __comp,
178 const allocator_type& __a = allocator_type())
179 : _M_t(__comp, _Key_alloc_type(__a))
180 { _M_t._M_insert_equal(__first, __last); }
189 multiset(
const multiset& __x)
192 #if __cplusplus >= 201103L
200 multiset(multiset&& __x)
201 noexcept(is_nothrow_copy_constructible<_Compare>::value)
202 : _M_t(std::move(__x._M_t)) { }
214 multiset(initializer_list<value_type> __l,
215 const _Compare& __comp = _Compare(),
216 const allocator_type& __a = allocator_type())
217 : _M_t(__comp, _Key_alloc_type(__a))
218 { _M_t._M_insert_equal(__l.begin(), __l.end()); }
229 operator=(
const multiset& __x)
235 #if __cplusplus >= 201103L
245 operator=(multiset&& __x)
266 operator=(initializer_list<value_type> __l)
269 this->insert(__l.begin(), __l.end());
279 {
return _M_t.key_comp(); }
283 {
return _M_t.key_comp(); }
286 get_allocator() const _GLIBCXX_NOEXCEPT
287 {
return allocator_type(_M_t.get_allocator()); }
295 begin() const _GLIBCXX_NOEXCEPT
296 {
return _M_t.begin(); }
304 end() const _GLIBCXX_NOEXCEPT
305 {
return _M_t.end(); }
313 rbegin() const _GLIBCXX_NOEXCEPT
314 {
return _M_t.rbegin(); }
322 rend() const _GLIBCXX_NOEXCEPT
323 {
return _M_t.rend(); }
325 #if __cplusplus >= 201103L
332 cbegin() const noexcept
333 {
return _M_t.begin(); }
341 cend() const noexcept
342 {
return _M_t.end(); }
350 crbegin() const noexcept
351 {
return _M_t.rbegin(); }
359 crend() const noexcept
360 {
return _M_t.rend(); }
365 empty() const _GLIBCXX_NOEXCEPT
366 {
return _M_t.empty(); }
370 size() const _GLIBCXX_NOEXCEPT
371 {
return _M_t.size(); }
375 max_size() const _GLIBCXX_NOEXCEPT
376 {
return _M_t.max_size(); }
391 { _M_t.swap(__x._M_t); }
394 #if __cplusplus >= 201103L
407 template<
typename... _Args>
409 emplace(_Args&&... __args)
410 {
return _M_t._M_emplace_equal(std::forward<_Args>(__args)...); }
433 template<
typename... _Args>
435 emplace_hint(const_iterator __pos, _Args&&... __args)
437 return _M_t._M_emplace_hint_equal(__pos,
438 std::forward<_Args>(__args)...);
454 insert(
const value_type& __x)
455 {
return _M_t._M_insert_equal(__x); }
457 #if __cplusplus >= 201103L
459 insert(value_type&& __x)
460 {
return _M_t._M_insert_equal(std::move(__x)); }
484 insert(const_iterator __position,
const value_type& __x)
485 {
return _M_t._M_insert_equal_(__position, __x); }
487 #if __cplusplus >= 201103L
489 insert(const_iterator __position, value_type&& __x)
490 {
return _M_t._M_insert_equal_(__position, std::move(__x)); }
501 template<
typename _InputIterator>
503 insert(_InputIterator __first, _InputIterator __last)
504 { _M_t._M_insert_equal(__first, __last); }
506 #if __cplusplus >= 201103L
515 insert(initializer_list<value_type> __l)
516 { this->insert(__l.begin(), __l.end()); }
519 #if __cplusplus >= 201103L
535 _GLIBCXX_ABI_TAG_CXX11
537 erase(const_iterator __position)
538 {
return _M_t.erase(__position); }
551 erase(iterator __position)
552 { _M_t.erase(__position); }
567 erase(
const key_type& __x)
568 {
return _M_t.erase(__x); }
570 #if __cplusplus >= 201103L
587 _GLIBCXX_ABI_TAG_CXX11
589 erase(const_iterator __first, const_iterator __last)
590 {
return _M_t.erase(__first, __last); }
605 erase(iterator __first, iterator __last)
606 { _M_t.erase(__first, __last); }
616 clear() _GLIBCXX_NOEXCEPT
627 count(
const key_type& __x)
const
628 {
return _M_t.count(__x); }
645 find(
const key_type& __x)
646 {
return _M_t.find(__x); }
649 find(
const key_type& __x)
const
650 {
return _M_t.find(__x); }
666 lower_bound(
const key_type& __x)
667 {
return _M_t.lower_bound(__x); }
670 lower_bound(
const key_type& __x)
const
671 {
return _M_t.lower_bound(__x); }
682 upper_bound(
const key_type& __x)
683 {
return _M_t.upper_bound(__x); }
686 upper_bound(
const key_type& __x)
const
687 {
return _M_t.upper_bound(__x); }
706 std::pair<iterator, iterator>
707 equal_range(
const key_type& __x)
708 {
return _M_t.equal_range(__x); }
710 std::pair<const_iterator, const_iterator>
711 equal_range(
const key_type& __x)
const
712 {
return _M_t.equal_range(__x); }
715 template<
typename _K1,
typename _C1,
typename _A1>
718 const multiset<_K1, _C1, _A1>&);
720 template<
typename _K1,
typename _C1,
typename _A1>
722 operator< (const multiset<_K1, _C1, _A1>&,
723 const multiset<_K1, _C1, _A1>&);
737 template<
typename _Key,
typename _Compare,
typename _Alloc>
739 operator==(
const multiset<_Key, _Compare, _Alloc>& __x,
740 const multiset<_Key, _Compare, _Alloc>& __y)
741 {
return __x._M_t == __y._M_t; }
754 template<
typename _Key,
typename _Compare,
typename _Alloc>
756 operator<(const multiset<_Key, _Compare, _Alloc>& __x,
757 const multiset<_Key, _Compare, _Alloc>& __y)
758 {
return __x._M_t < __y._M_t; }
761 template<
typename _Key,
typename _Compare,
typename _Alloc>
763 operator!=(
const multiset<_Key, _Compare, _Alloc>& __x,
764 const multiset<_Key, _Compare, _Alloc>& __y)
765 {
return !(__x == __y); }
768 template<
typename _Key,
typename _Compare,
typename _Alloc>
770 operator>(
const multiset<_Key,_Compare,_Alloc>& __x,
771 const multiset<_Key,_Compare,_Alloc>& __y)
772 {
return __y < __x; }
775 template<
typename _Key,
typename _Compare,
typename _Alloc>
777 operator<=(const multiset<_Key, _Compare, _Alloc>& __x,
778 const multiset<_Key, _Compare, _Alloc>& __y)
779 {
return !(__y < __x); }
782 template<
typename _Key,
typename _Compare,
typename _Alloc>
784 operator>=(
const multiset<_Key, _Compare, _Alloc>& __x,
785 const multiset<_Key, _Compare, _Alloc>& __y)
786 {
return !(__x < __y); }
789 template<
typename _Key,
typename _Compare,
typename _Alloc>
791 swap(multiset<_Key, _Compare, _Alloc>& __x,
792 multiset<_Key, _Compare, _Alloc>& __y)
795 _GLIBCXX_END_NAMESPACE_CONTAINER
bool operator>=(const _Safe_iterator< _IteratorL, _Sequence > &__lhs, const _Safe_iterator< _IteratorR, _Sequence > &__rhs)
Definition: safe_iterator.h:644
bool operator==(const exception_ptr &, const exception_ptr &) _GLIBCXX_USE_NOEXCEPT __attribute__((__pure__))
#define __glibcxx_class_requires(_a, _b)
Definition: concept_check.h:48
bool operator>(const _Safe_iterator< _IteratorL, _Sequence > &__lhs, const _Safe_iterator< _IteratorR, _Sequence > &__rhs)
Definition: safe_iterator.h:612
#define __glibcxx_class_requires2(_a, _b, _c)
Definition: concept_check.h:49
bool operator!=(const exception_ptr &, const exception_ptr &) _GLIBCXX_USE_NOEXCEPT __attribute__((__pure__))
void swap(exception_ptr &__lhs, exception_ptr &__rhs)
Definition: exception_ptr.h:160
#define __glibcxx_class_requires4(_a, _b, _c, _d, _e)
Definition: concept_check.h:51