|
|
The multiset class supports a set in which possibly nonunique keys are mapped with values. Its template specification is shown here:
template <class Key, class Comp = less<Key>,
class Allocator = allocator<Key> > class multiset
Here, Key is the data of the keys and Comp is a function that compares two keys. It has the following constructors:
explicit multiset(const Comp &cmpfn = Comp( ),
const Allocator &a = Allocator( ) );
multiset(const multiset<Key, Comp, Allocator> &ob);
template <class InIter> multiset(InIter start, InIter end,
const Comp &cmpfn = Comp( ),
const Allocator &a = Allocator( ));
The first form constructs an empty multiset. The second form constructs a multiset that contains the same elements as ob. The third form constructs a multiset that contains the elements in the range specified by start and end. The function specified by cmpfn, if present, determines the ordering of the set.
The following comparison operators are defined for multiset:
==, <, <=, !=, >, >=
The member functions contained by multiset are shown here. In the descriptions, both key_type and value_type are typedefs for Key.
Member | Description |
---|---|
iterator begin( ); | Returns an iterator to the first element in the multiset. |
void clear( ); | Removes all elements from the multiset. |
size_type count(const key_type &k) const; | Returns the number of times k occurs in the multiset. |
bool empty( ) const; | Returns true if the invoking multiset is empty and false otherwise. |
iterator end( ); | Returns an iterator to the end of the list. |
pair<iterator, iterator> | Returns a pair of iterators that point to the first and last elements in the multiset that contain the specified key. |
void erase(iterator i); | Removes the element pointed to by i. |
void erase(iterator start, iterator end); | Removes the elements in the range start to end. |
size_type erase(const key_type &k); | Removes from the multiset elements that have keys with the value k. |
iterator find(const key_type &k) const; | Returns an iterator to the specified key. If the key is not found, then an iterator to the end of the multiset is returned. |
allocator_type get_allocator( ) const; | Returns multiset’s allocator. |
iterator insert(iterator i, | Inserts val at or after the element specified by i. An iterator to the element is returned. |
template <class InIter> | Inserts a range of elements. |
iterator insert(const value_type &val); | Inserts val into the invoking multiset. An iterator to the element is returned. |
key_compare key_comp( ) const; | Returns the function object that compares keys. |
iterator lower_bound(const key_type &k) | Returns an iterator to the first element in the multiset with the key equal to or greater than k. |
size_type max_size( ) const; | Returns the maximum number of elements that the multiset can hold. |
reverse_iterator rbegin( ); | Returns a reverse iterator to the end of the multiset. |
reverse_iterator rend( ); | Returns a reverse iterator to the start of the multiset. |
size_type size( ) const; | Returns the number of elements currently in the multiset. |
void swap(multiset<Key, Comp, | Exchanges the elements stored in the invoking multiset with those in ob. |
iterator upper_bound(const key_type &k) | Returns an iterator to the first element in the multiset with the key greater than k. |
value_compare value_comp( ) const; | Returns the function object that compares values. |
|
|