mace::MapIterator< M > Class Template Reference

#include <Iterator.h>

List of all members.


Detailed Description

template<typename M>
class mace::MapIterator< M >

Java-style iteration for C++ collections (next/hasNext).

implemented by always storing an iterator to the last item as well as the next (unretrieved) item. Calling next() advances the iterator, returning a reference to the item. Items can be removed using the remove() method, which calls erase on the map with the last iterator. Whether the iteration reaches all elements will have to do with the properties of the collection if you erase during iteration (for sorted collections, it will generally work), but it shouldn't break in either circumstance.

Example:

 mace::map<int, int> m;
 //insert a bunch of members into m
 mace::MapIterator<mace::map<int, int> > i(m);
 while (i.hasNext()) {
   int& key;
   int& value = i.next(key);
   if (key != value) {
     i.remove();
   }
 }

Definition at line 76 of file Iterator.h.


Public Member Functions

 MapIterator (M &s)
 Constructs the map iterator from a map reference (iterator over the whole map).
 MapIterator (M &s, iterator b)
 Constructs the map iterator from a map reference and a beginning point (iterates to end()).
 MapIterator (M &s, iterator b, iterator e)
 Constructs the map iterator from a map reference, a beginning point, and an ending point.
bool hasNext ()
 returns whether there are more elements
V & next ()
 returns the present (next) item by reference, advancing the iterators
V & next (K &key)
 returns the present (next) item by reference, and makes a copy of the key into the key reference, advancing the iterators
void remove ()
 removes the item last retrieved by next()

The documentation for this class was generated from the following file:

Generated on Sat Oct 4 21:30:38 2008 for Mace Library by  doxygen 1.5.5