#include "map.h"
Public Member Functions | |
| Iterator () | |
| bool | hasNext () |
| string | next () |
Friends | |
| class | Map |
The idiomatic code for accessing elements using an iterator is to create the iterator from the collection and then enter a loop that calls next() while hasNext() is true, like this:
Map<int>::Iterator itr = map.iterator(); while (itr.hasNext()) string key = itr.next();
| Map< ValueType >::Iterator::Iterator | ( | ) |
The Iterator for Map tracks a pointer to the original Map and a vector containing of the map keys that was assembled at the time of iteration creation. The iterator tracks an index into that vector that identifies the next key to return. Each use of next() increments that index, hasNext() verifies the index < the vector's size. This is an example of an "offline" iterator because it copies the map's data, instead of accessing it in-place. This is a bit inefficient (since it copies) but it makes the iterator simplier to write and sidesteps any problems where the client is modifying the map during iteration.
| bool Map< ValueType >::Iterator::hasNext | ( | ) |
| string Map< ValueType >::Iterator::next | ( | ) |
friend class Map [friend] |
1.5.1