Map-Based Iteration and Pairs
In the case of a map-based collection class, like RWTValMap<K,T,C,A>, iterators refer to instances of the C++ Standard Library structure pair<const K, T>. As you iterate over a map-based collection, you have access to both the key and its associated data at each step along the traversal. The pair structure provides members first and second, which allow you to individually access the key and its data, respectively. For example:
 
typedef RWTValMap<RWCString,
RWDateTime, std::less<RWCString> > Datebook;
Datebook birthdays;
// ... < populate birthdays collection >
Datebook::iterator iter = birthdays.begin();
while (iter != birthdays.end()) {
std::cout << (*iter).first // the key
<< " was born on "
<< (*iter).second // the data for that key
<< std::endl;
++iter;
};
Note that given a non-const reference to such a pair, you can still modify only the second element—the data associated with the key. This is because the first element is declared to be of type const K. Because the placement of objects within the collection class is maintained internally, based on the value of the key, declaring it as const protects the integrity of the collection class. In order to change a key within a map, you have to remove the key and its data entirely, and replace them with a new entry.