C++ map Library
C++ map Functions
The <map> library has functions that let you add, find and remove elements in a map. A map stores elements in key/value pairs, sorted by key, and every key is unique.
Many of the functions return an iterator (a pointer-like object that points to an element). For a map element, it->first is the key and it->second is the value.
| Function | Description |
|---|---|
| at() | Returns the value of the element with the given key |
| begin() | Returns an iterator to the first element of a map |
| clear() | Removes all elements from a map |
| count() | Returns 1 if a key exists in a map, and 0 if it does not |
| emplace() | Adds a new element to a map, built from a key and a value |
| empty() | Checks whether a map is empty or not |
| end() | Returns an iterator to the position after the last element of a map |
| erase() | Removes one or more elements from a map |
| find() | Searches for a key, and returns an iterator to the element |
| insert() | Adds one or more elements to a map |
| lower_bound() | Returns an iterator to the first element with a key that is equal to or greater than a given key |
| rbegin() | Returns a reverse iterator to the last element of a map |
| rend() | Returns a reverse iterator to the position before the first element of a map |
| size() | Returns the number of elements in a map |
| swap() | Swaps the contents of two maps |
| upper_bound() | Returns an iterator to the first element with a key that is greater than a given key |