queue

multimap

The multimap class supports an associative container in which possibly nonunique keys are mapped with values. Its template specification is shown here:

template <class Key, class T, class Comp = less<Key>,
                class Allocator = allocator<pair<const Key, T> > >
                class multimap

Here, Key is the data of the keys, T is the data type of the values being stored (mapped), and Comp is a function that compares two keys. It has the following constructors:

explicit multimap(const Comp &cmpfn = Comp( ),
                const Allocator &a = Allocator( ) );
multimap(const multimap<Key, T, Comp, Allocator> &ob);
template <class InIter> multimap(InIter start, InIter end,
                const Comp &cmpfn = Comp( ),
                const Allocator &a = Allocator( ));

The first form constructs an empty multimap. The second form constructs a multimap that contains the same elements as ob. The third form constructs a multimap that contains the elements in the range specified by start and end. The function specified by cmpfn, if present, determines the ordering of the multimap.

The following comparison operators are defined by multimap:

==, <, <=, !=, >, >=

The member functions contained by multimap are shown here. In the descriptions, key_type is the type of the key, T is the value, and value_type represents pair<Key, T>.

Member

Description

iterator begin( );
const_iterator begin( ) const;

Returns an iterator to the first element in the multimap.

void clear( );

Removes all elements from the multimap.

size_type count(const key_type &k) const;

Returns the number of times k occurs in the multimap.

bool empty( ) const;

Returns true if the invoking multimap is empty and false otherwise.

iterator end( );
const_iterator end( ) const;

Returns an iterator to the end of the list.

pair<iterator, iterator>
   equal_range(const key_type &k);
pair<const_iterator, const_iterator>
   equal_range(const key_type &k) const;

Returns a pair of iterators that point to the first and last elements in the multimap 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 multimap elements that have keys with the value k.

iterator find(const key_type &k);
const_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 multimap is returned.

allocator_type get_allocator( ) const;

Returns multimap’s allocator.

iterator insert(iterator i,
                        const value_type &val);

Inserts val at or after the element specified by i. An iterator to the element is returned.

template <class InIter>
   void insert(InIter start, InIter end);

Inserts a range of elements.

iterator insert(const value_type &val);

Inserts val into the invoking multimap.

key_compare key_comp( ) const;

Returns the function object that compares keys.

iterator lower_bound(const key_type  &k);
const_iterator
   lower_bound(const key_type &k) const;

Returns an iterator to the first element in the multimap with the key equal to or greater than k.

size_type max_size( ) const;

Returns the maximum number of elements that the multimap can hold.

reverse_iterator rbegin( );
const_reverse_iterator rbegin( ) const;

Returns a reverse iterator to the end of the multimap.

reverse_iterator rend( );
const_reverse_iterator rend( ) const;

Returns a reverse iterator to the start of the multimap.

size_type size( ) const;

Returns the number of elements currently in the multimap.

void swap(multimap<Key, T, Comp,
                  Allocator> &ob);

Exchanges the elements stored in the invoking multimap with those in ob.

iterator upper_bound(const key_type  &k);
const_iterator
   upper_bound(const key_type &k) const;

Returns an iterator to the first element in the multimap with the key greater than k.

value_compare value_comp( ) const;

Returns the function object that compares values.




C(s)C++ Programmer's Reference
C Programming on the IBM PC (C Programmers Reference Guide Series)
ISBN: 0673462897
EAN: 2147483647
Year: 2002
Pages: 539

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net