C++ Library - <map>

Map is dictionary like data structure. It is a sequence of (key, value) pair, where only single value is associated with each unique key. It is often referred as associative array.
In map key values generally used to sort the elements. For map data type of key and value can differ and it is represented as
typedef pair<const Key, T> value_type;

Maps are typically implemented as Binary Search Tree.
Zero sized maps are also valid. In that case map.begin() and map.end() points to same location.
Below is definition of std::map from <map> header file
template < class Key,
           class T,
           class Compare = less<Key>,
           class Alloc = allocator<pair<const Key,T> >
           > class map;

Key − Type of the key.
Key − Type of the key.
T − Type of the mapped values.
T − Type of the mapped values.
Compare − A binary predicate that takes two element keys as arguments and returns a bool.
Compare − A binary predicate that takes two element keys as arguments and returns a bool.
Alloc − Type of the allocator object.
Alloc − Type of the allocator object.
T may be substituted by any other data type including user-defined type.
Following member types can be used as parameters or return type by member functions.
Below is list of all methods from <map> header.
Constructs an empty map with zero elements.
Constructs a map with as many elements as in range of first to last.
Constructs a map with copy of each elements present in existing map.
Constructs a map with the contents of other using move semantics.
Constructs a map from initialize list.
Destroys map object by deallocating it's memory.
Returns a reference to the mapped value associated with key k.
Returns a iterator which refers to the first element of the map.
Returns a constant iterator which refers to the first element of the map.
Returns a constant iterator which points to past-the-end element of the map.
Destroys the map by removing all elements and sets size of map to zero.
Returns number of mapped values associated with key k.
Returns a constant reverse iterator which points to the last element of the container i.
Returns a constant reverse iterator which points to the theoretical element preceding the first element in the container i.
Extends container by inserting new element.
Inserts a new element in a map using hint as a position for element.
Tests whether map is empty or not.
Returns an iterator which points to past-the-end element in the map.
Returns range of elements that matches specific key.
Removes single element of the map from position.
Removes single element of the map from position.
Removes mapped value associated with key k.
Removes range of element from the the map.
Removes range of element from the the map.
Finds an element associated with key k.
Returns an allocator associated with map.
Extends container by inserting new element in map.
Extends container by inserting new element in map.
Extends container by inserting new elements in the map.
Extends map by inserting new element.
Extends map by inserting new element from initializer list.
Returns a function object that compares the keys, which is a copy of this container's constructor argument comp.
Returns an iterator pointing to the first element which is not less than key k.
Returns the maximum number of elements can be held by map.
Assign new contents to the map by replacing old ones and modifies size if necessary.
Move the contents of one map into another and modifies size if necessary.
Copy elements from initializer list to map.
If key k matches an element in the container, then method returns a reference to the element.
If key k matches an element in the container, then method returns a reference to the element.
Returns a reverse iterator which points to the last element of the map.
Returns a reverse iterator which points to the reverse end of the map i.
Returns the number of elements present in the map.
Exchanges the content of map with contents of map x.
Returns an iterator pointing to the first element which is greater than key k.
Returns a function object that compares objects of type std::map::value_type.
Tests whether two maps are equal or not.
Tests whether two maps are equal or not.
Tests whether first map is less than other or not.
Tests whether first map is less than or equal to other or not.
Tests whether first map is greater than other or not.
Tests whether first map is greater than or equal to other or not.
Exchanges the content of map with contents of map x.
Multimap is dictionary like data structure. It is a sequence of (key, value) pair, where multiple values can be associate with equivalent keys. It is often referred as associative array.
In multimap key values generally used to sort the elements. For multimap data type of key and value can differ and it is represented as
typedef pair<const Key, T> value_type;

Multimaps are typically implemented as Binary Search Tree.
Zero sized multimaps are also valid. In that case multimap.begin() and multimap.end() points to same location.
Below is definition of std::multimap from <multimap> header file
template < class Key,
           class T,
           class Compare = less<Key>,
           class Alloc = allocator<pair<const Key,T> >
           > class multimap;

Key − Type of the key.
Key − Type of the key.
T − Type of the mapped values.
T − Type of the mapped values.
Compare − A binary predicate that takes two element keys as arguments and returns a bool.
Compare − A binary predicate that takes two element keys as arguments and returns a bool.
Alloc − Type of the allocator object.
Alloc − Type of the allocator object.
T may be substituted by any other data type including user-defined type.
Following member types can be used as parameters or return type by member functions.
Below is list of all methods from <multimap> header.
Constructs an empty multimap with zero elements.
Constructs a multimap with as many elements as in range of first to last.
Constructs a multimap with copy of each elements present in existing multimap.
Constructs a multimap with the contents of other using move semantics.
Constructs a multimap from initialize list.
Destroys multimap object by deallocating it's memory.
Returns a iterator which refers to the first element of the multimap.
Returns a constant iterator which refers to the first element of the multimap.
Returns a constant iterator which points to past-the-end element of the multimap.
Destroys the multimap by removing all elements and sets size of multimap to zero.
Returns number of multimapped values associated with key k.
Returns a constant reverse iterator which points to the last element of the container.
Returns a constant reverse iterator which points to the theoretical element preceding the first element in the container.
Extends container by inserting new element.
Inserts a new element in a multimap using hint as a position for element.
Tests whether multimap is empty or not.
Returns an iterator which points to past-the-end element in the multimap.
Returns range of elements that matches specific key.
Removes single element of the multimap from position.
Removes single element of the multimap from position.
Removes mapped value associated with key k.
Removes range of element from the the multimap.
Removes range of element from the the multimap.
Finds an element associated with key k.
Returns an allocator associated with multimap.
Extends container by inserting new element in multimap.
Extends container by inserting new element in multimap.
Extends container by inserting new elements in the multimap.
Extends multimap by inserting new element.
Extends multimap by inserting new element from initializer list.
Returns a function object that compares the keys, which is a copy of this container's constructor argument comp.
Returns an iterator pointing to the first element which is not less than key k.
Returns the maximum number of elements can be held by multimap.
Assign new contents to the multimap by replacing old ones and modifies size if necessary.
Move the contents of one multimap into another and modifies size if necessary.
Copy elements from initializer list to multimap.
Returns a reverse iterator which points to the last element of the multimap.
Returns a reverse iterator which points to the reverse end of the multimap.
Returns the number of elements present in the multimap.
Exchanges the content of multimap with contents of multimap x.
Returns an iterator pointing to the first element which is greater than key k.
Returns a function object that compares objects of type std::multimap::value_type.
Tests whether two multimaps are equal or not.
Tests whether two multimaps are equal or not.
Tests whether first multimap is less than other or not.
Tests whether first multimap is less than or equal to other or not.
Tests whether first multimap is greater than other or not.
Tests whether first multimap is greater than or equal to other or not.
Exchanges the content of multimap with contents of multimap x.
 Print
 Add Notes
 Bookmark this page