multiset

map

The map class supports an associative container in which unique 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 map

Here, Key is the data type 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 map(const Comp &cmpfn = Comp( ),
                const Allocator &a = Allocator( ) );
map(const map<Key, T, Comp, Allocator> &ob);
template <class InIter> map(InIter start, InIter end,
                const Comp &cmpfn = Comp( ),
                const Allocator &a = Allocator( ));

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

The following comparison operators are defined for map:

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

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

Member

Description

iterator begin( );
const_iterator begin( ) const;

Returns an iterator to the first element in the map.

void clear( );

Removes all elements from the map.

size_type count(const key_type &k) const;

Returns the number of times k occurs in the map (1 or 0).

bool empty( ) const;

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

iterator end( );
const_iterator end( ) const;

Returns an iterator to the end of the map.

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 map 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 map 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 map is returned.

allocator_type get_allocator( ) const;

Returns map’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.

pair<iterator, bool>
   insert(const value_type &val);

Inserts val into the invoking map. An iterator to the element is returned. The element is inserted only if it does not already exist. If the element was inserted, pair<iterator, true> is returned. Otherwise, pair<iterator, false> is returned.

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 map with the key equal to or greater than k.

size_type max_size( ) const;

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

mapped_type &
   operator[ ](const key_type &i);

Returns a reference to the element specified by i. If this element does not exist, it is inserted.

reverse_iterator rbegin( );
const_reverse_iterator rbegin( ) const;

Returns a reverse iterator to the end of the map.

reverse_iterator rend( );
const_reverse_iterator rend( ) const;

Returns a reverse iterator to the start of the map.

size_type size( ) const;

Returns the number of elements currently in the map.

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

Exchanges the elements stored in the invoking map 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 map 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