Navigation: Up, Table of Contents, Bibliography, Index, Title Page

map (map)

Definition

An object of the class map<Key, T, Compare> supports unique keys of type Key, and provides retrieval of values of type T based on the keys. The keys into the map are ordered by the ordering relation Compare.

Elements are stored in maps as pairs of Key and T.

#include <map.h>

Types

map<Key, T, Compare>::iterator
A const bidirectional iterator.

Creation

map<Key, T, Compare> M ( Compare comp = Compare());
Introduces an empty map.

map<Key, T, Compare> M ( map<Key, T, Compare> M1);
Copy constructor.

Operations

map<Key, T, Compare> & M = map<Key, T, Compare> M1
Assignment.
bool M == map<Key, T, Compare> M1
Equality test: Two maps are equal, if the sequences M and M1 are elementwise equal.
bool M < map<Key, T, Compare> M1
Returns true if M is lexicographically less than M1, false otherwise.
iterator M.begin () Returns a constant iterator referring to the first element in map M.
iterator M.end () Returns a constant past-the-end iterator of map M.
bool M.empty () Returns true if M is empty.
int M.size () Returns the number of items in map M.
T& M [ Key k] Returns a reference to the type T value associated with key k. If the map is constant then a const reference is returned. In contrast to vector or deque, the pair(k,T()) is inserted into the map, if no element is associated with the key.

Insert and Erase

iterator M.insert ( iterator pos, pair< Key ,T> val)
Inserts val into the map if val is not already present in M. The iterator pos is the starting point of the search. The return value points to the inserted item.
pair<iterator, bool> M.insert ( pair< Key ,T> val)
Inserts val into the map if val is not already present in M. Returns a pair, where first is the iterator that points to the inserted item or to the item that is already present in M, and where second is true if the insertion took place.
void M.erase ( iterator pos) Erases the element where pos points to.
int M.erase ( Key k) Erases all elements that equal k. Returns the number of erased elements.

Miscellaneous

iterator M.find ( Key k) Returns an iterator that either points to the element k, or end() if k is not present in map M.
int M.count ( Key k) Returns the number of occurrences of k in map M.
iterator M.lower_bound ( Key k) Returns an iterator that points to the first element of M that is not less than k. If all elements are less than k then end() is returned. If k is present in the map the returned iterator points to k.
iterator M.upper_bound ( Key k) Returns an iterator that points to the first element of the map that is greater than k. If no element is greater than k then end() is returned. If k is present in the map the returned iterator points to k.


Next: Class declaration of multimap<Key, T, Compare>
Navigation: Up, Table of Contents, Bibliography, Index, Title Page
The CGAL Project. Mon, June 30, 1997.