One, foreword

The only difference between a multiset and a set is that a multiset can store multiple elements with the same value, while a set can store only different elements.

Multiset class template definition:

Template < class T, class Compare = less<T>, Class Alloc = allocator<T> > // Allocator object type > class multiset;

The multiset class template has three parameters, the last two of which come with default values. In practice, we only need to use the first two parameters at most, and the third parameter will not be used.

Create a multiset

The constructor provided by the MultiSet class template is identical to the constructor provided by the Set class template to create the Set container. So the same way you create a set applies to creating a multiset. Specific method reference set container: https://segmentfault.com/a/11…

Three, methods,

methods instructions
begin() Returns a bidirectional iterator that refers to the first (note, sorted) element in the container. If the multiset is const, then this method returns a bidirectional iterator of type const
end() Returns a bidirectional iterator that refers to the position after the last element (note, the last one sorted) in the container. It is usually used in conjunction with begin(). If the multiset is const, then this method returns a bidirectional iterator of type const
rbegin() Returns a reverse bidirectional iterator referring to the last (note, the last sorted) element. If the multiset is const, then this method returns a reverse bidirectional iterator of const type.
rend() Returns a reverse bidirectional iterator to the position before the position of the first (note, the first sorted) element. If the multiset is const, then this method returns a reverse bidirectional iterator of const type.
cbegin() Begin () is the same as begin(), but adds a const attribute that cannot be used to modify the value of an element stored in a container
cend() End () has the same function as end(), but adds a const attribute that cannot be used to change the value of an element stored in a container.
crbegin() Rbegin () has the same function as rbegin(), but adds a const attribute that cannot be used to change the value of an element stored in a container
crend() Rend () has the same function as rend(), but adds a const attribute that cannot be used to change the value of an element stored in a container
find(val) Returns a bidirectional iterator to the element in the multiset if the value of val is found. Otherwise, it returns the same iterator as the end() method. In addition, if the multiset is const qualified, the method returns a bidirectional iterator of type const
lower_bound(val) Returns a bidirectional iterator that refers to the first element in the current multiset that is less than or equal to val. If the multiset is const, then this method returns a bidirectional iterator of type const
upper_bound(val) Returns an iterator that refers to the first element greater than val in the current multiset. If the multiset is const, then this method returns a bidirectional iterator of type const
equal_range(val) This method returns a pair containing two bidirectional iterators, where pair.first and lower_bound() return the same value, and upper_bound() return the same value. That is, the method returns a range containing all elements with a value of val
empty() Returns true if the container is empty; Otherwise, false
size() Returns the number of elements in the current multiset
max_size() Returns the maximum number of elements that can be contained in a multiset. This value may vary by operating system
insert() Inserts an element into a multiset
erase() Deletes the specified element stored in a multiset
swap() Swap all elements stored in two multisets. This means that the two multisets of the operation must be of the same type
clear() Clear the multiset of all the elements, that is, size() is 0
emplace() Constructs the new element directly at the specified location in the current multiset. The effect is the same as insert(), but more efficient
emplace_hint() Essentially the same way emplace() constructs a new element in a multiset, except that the user must supply the method with an iterator indicating where the new element is generated as the first argument to the method
count(val) Returns the number of elements in the current multiset with the value val

The count(), find(), lower_bound(), upper_bound(), equal_range() and other methods are more commonly used in multisets than in sets.

1, the sample