Used for the storage and retrieval of data from a collection in which each element is a pair that has both a data value and a sort key. The value of the key is unique and is used to automatically sort the data.
The value of an element in a map can be changed directly. The key value is a constant and cannot be changed. Instead, key values associated with old elements must be deleted, and new key values must be inserted for new elements.
template < class Key, class Type, class Traits = less<Key>, class Allocator=allocator<pair <const Key, Type> > > class map
The Standard Template Library (STL) map class is:
A container of variable size that efficiently retrieves element values based on associated key values.
Reversible, because it provides bidirectional iterators to access its elements.
Sorted, because its elements are ordered by key values according to a specified comparison function.
Unique. because each of its elements must have a unique key.
A pair-associative container, because its element data values are distinct from its key values.
A template class, because the functionality it provides is generic and independent of element or key type. The data types used for elements and keys are specified as parameters in the class template together with the comparison function and allocator.
The iterator provided by the map class is a bidirectional iterator, but the insert and map class member functions have versions that take as template parameters a weaker input iterator, whose functionality requirements are fewer than those guaranteed by the class of bidirectional iterators. The different iterator concepts are related by refinements in their functionality. Each iterator concept has its own set of requirements, and the algorithms that work with it must be limited by those requirements. An input iterator may be dereferenced to refer to some object and may be incremented to the next iterator in the sequence.
We recommend that you base the choice of container type on the kind of searching and inserting that is required by the application. Associative containers are optimized for the operations of lookup, insertion, and removal. The member functions that explicitly support these operations perform them in a worst-case time that is proportional to the logarithm of the number of elements in the container. Inserting elements invalidates no iterators, and removing elements invalidates only those iterators that specifically pointed to the removed elements.
We recommend that you make the map the associative container of choice when conditions that associate values with keys are satisfied by the application. A model for this kind of structure is an ordered list of uniquely occurring key words that have associated string values that provide definitions. If a word has more than one correct definition, so that key is not unique, then a multimap would be the container of choice. If just the list of words is being stored, then a set would be the appropriate container. If multiple occurrences of the words are allowed, then a multiset would be appropriate.
The map orders the elements it controls by calling a stored function object of type key_compare. This stored object is a comparison function that is accessed by calling the key_comp method. In general, any two given elements are compared to determine whether one is less than the other or whether they are equivalent. As all elements are compared, an ordered sequence of non-equivalent elements is created.
The comparison function is a binary predicate that induces a strict weak ordering in the standard mathematical sense. A binary predicate f(x,y) is a function object that has two argument objects x and y, and a return value of true or false. An ordering imposed on a set is a strict weak ordering if the binary predicate is irreflexive, antisymmetric, and transitive, and if equivalence is transitive, where two objects x and y are defined to be equivalent when both f(x,y)and f(y,x) are false. If the stronger condition of equality between keys replaces that of equivalence, the ordering becomes total (in the sense that all the elements are ordered with regard to one other), and the keys matched will be indiscernible from one other.
Constructs a list of a specific size or with elements of a specific value or with a specific allocator or as a copy of some other map.
A typedef for the allocator class for the map object.
A typedef for a bidirectional iterator that can read a const element in the map.
A typedef for a pointer to a const element in a map.
A typedef for a reference to a const element stored in a map for reading and performing const operations.
A type that provides a bidirectional iterator that can read any const element in the map.
A signed integer typedef for the number of elements of a map in a range between elements pointed to by iterators.
A typedef for a bidirectional iterator that can read or modify any element in a map.
A typedef for a function object that can compare two sort keys to determine the relative order of two elements in the map.
A typedef for the sort key stored in each element of the map.
A typedef for the data stored in each element of a map.
A typedef for a pointer to a const element in a map.
A typedef for a reference to an element stored in a map.
A typedef for a bidirectional iterator that can read or modify an element in a reversed map.
An unsigned integer typedef for the number of elements in a map
A typedef for the type of object stored as an element in a map.
Finds an element with a specified key value.
Returns an iterator that points to the first element in the map.
Returns a const iterator that points to the first element in the map.
Returns a const past-the-end iterator.
Erases all the elements of a map.
Returns the number of elements in a map whose key matches the key specified in a parameter.
Returns a const iterator that points to the first element in a reversed map.
Returns a const iterator that points to the location after the last element in a reversed map.
Inserts an element constructed in place into the map.
Inserts an element constructed in place into the map, with a placement hint.
Returns true if a map is empty.
Returns the past-the-end iterator.
Returns a pair of iterators. The first iterator in the pair points to the first element in a map with a key that is greater than a specified key. The second iterator in the pair points to the first element in the map with a key that is equal to or greater than the key.
Removes an element or a range of elements in a map from the specified positions.
Returns an iterator that points to the location of an element in a map that has a key equal to a specified key.
Returns a copy of the allocator object that is used to construct the map.
Inserts an element or a range of elements into the map at a specified position.
Returns a copy of the comparison object that used to order keys in a map.
Returns an iterator to the first element in a map that has a key value that is equal to or greater than that of a specified key.
Returns the maximum length of the map.
Returns an iterator that points to the first element in a reversed map.
Returns an iterator that points to the location after the last element in a reversed map.
Returns the number of elements in the map.
Exchanges the elements of two maps.
Returns an iterator to the first element in a map that has a key value that is greater than that of a specified key.
Retrieves a copy of the comparison object that is used to order element values in a map.