DescriptionAn Associative Container is a variable-sized Container that supports efficient retrieval of elements (values) based on keys. It supports insertion and removal of elements, but differs from a Sequence in that it does not provide a mechanism for inserting an element at a specific position. 
As with all containers, the elements in an Associative Container are of type value_type. Additionally, each element in an Associative Container has a key, of type key_type. In some Associative Containers, Simple Associative Containers, the value_type and key_type are the same: elements are their own keys. In others, the key is some specific part of the value. Since elements are stored according to their keys, it is essential that the key associated with each element is immutable. In Simple Associative Containers this means that the elements themselves are immutable, while in other types of Associative Containers, such as Pair Associative Containers, the elements themselves are mutable but the part of an element that is its key cannot be modified. This means that an Associative Container's value type is not Assignable.
The fact that the value type of an Associative Container is not Assignable has an important consequence: associative containers cannot have mutable iterators. This is simply because a mutable iterator (as defined in the Trivial Iterator requirements) must allow assignment. That is, if i is a mutable iterator and t is an object of i's value type, then *i = t must be a valid expression.
In Simple Associative Containers, where the elements are the keys, the elements are completely immutable; the nested types iterator and const_iterator are therefore the same. Other types of associative containers, however, do have mutable elements, and do provide iterators through which elements can be modified. Pair Associative Containers, for example, have two different nested types iterator and const_iterator. Even in this case, iterator is not a mutable iterator: as explained above, it does not provide the expression *i = t. It is, however, possible to modify an element through such an iterator: if, for example, i is of type map<int, double>, then (*i).second = 3 is a valid expression.
In some associative containers, Unique Associative Containers, it is guaranteed that no two elements have the same key.  In other associative containers, Multiple Associative Containers, multiple elements with the same key are permitted.
Refinement ofForward Container, Default Constructible
Associated typesOne new type is introduced, in addition to the types defined in the Forward Container requirements.
DefinitionsIf a is an associative container, then p is a valid iterator in a if it is a valid iterator that is reachable from a.begin().
If a is an associative container, then [p, q) is a valid range in a if [p, q) is a valid range and p is a valid iterator in a.
Valid expressionsIn addition to the expressions defined in Forward Container, the following expressions must be valid.
Complexity guaranteesAverage complexity for erase key is at most O(log(size()) + count(k)).
Average complexity for erase element is constant time.
Average complexity for erase range is at most O(log(size()) + N), where N is the number of elements in the range.
Average complexity for count is at most O(log(size()) + count(k)).
Average complexity for find is at most logarithmic.
Average complexity for equal range is at most logarithmic.
 The reason there is no such mechanism is that the way in which elements are arranged in an associative container is typically a class invariant; elements in a Sorted Associative Container, for example, are always stored in ascending order, and elements in a Hashed Associative Container are always stored according to the hash function. It would make no sense to allow the position of an element to be chosen arbitrarily.
 Keys are not required to be Equality Comparable: associative containers do not necessarily use operator== to determine whether two keys are the same. In Sorted Associative Containers, for example, where keys are ordered by a comparison function, two keys are considered to be the same if neither one is less than the other.
 Note the implications of this member function: it means that if two elements have the same key, there must be no elements with different keys in between them. The requirement that elements with the same key be stored contiguously is an associative container invariant.
See alsoSimple Associative Container, Pair Associative Container, Unique Associative Container, Multiple Associative Container, Sorted Associative Container, Unique Sorted Associative Container, Multiple Sorted Associative Container, Hashed Associative Container, Unique Hashed Associative Container, Multiple Hashed Associative Container.
Copyright © 1999 Silicon Graphics, Inc. All Rights Reserved. TrademarkInformation