Insertion and access, Removal of values – HP Integrity NonStop H-Series User Manual
Page 99

key_type
The type associated with the keys used to index the map.
value_type
The type held by the container, a key/value pair.
const_iterator
An iterator that does not allow modification of the underlying
sequence.
reverse_iterator
An iterator that moves in a backward direction.
const_reverse_iterator A combination constant and reverse iterator.
reference
A reference to an underlying value.
const_reference
A reference to an underlying value that will not permit the element to
be modified.
size_type
An unsigned integer type, used to refer to the size of containers.
key_compare
A function object that can be used to compare two keys.
value_compare
A function object that can be used to compare two elements.
difference_type
A signed integer type, used to describe the distances between
iterators.
Insertion and Access
Values can be inserted into a map or a multimap using the insert() operation. Note that the
argument must be a key-value pair. This pair is often constructed using the data type value_type
associated with the map.
map_three.insert (map
Insertions can also be performed using an iterator pair, for example as generated by another
map.
map_two.insert (map_three.begin(), map_three.end());
With a map (but not a multimap), values can be accessed and inserted using the subscript
operator. Simply using a key as a subscript creates an entry - the default element is used as the
associated value. Assigning to the result of the subscript changes the associated binding.
cout << "Index value 7 is " << map_three[7] << endl;
// now change the associated value
map_three[7] = 5;
cout << "Index value 7 is " << map_three[7] << endl;
Removal of Values
Values can be removed from a map or a multimap by naming the key value. In a multimap the
erasure removes all elements with the associated key. An element to be removed can also be
denoted by an iterator; as, for example, the iterator yielded by a find() operation. A pair of
iterators can be used to erase an entire range of elements.