A common pattern with STL containers is this:
map map;
for(map::iterator iter = map.begin(); iter != map.end(); ++iter)
{
.
Over the past few years I've really tried to move away from using manually written loops in preference to using the STL algorithms. Your above code can be changed to:
struct DoLoopBody {
template
inline void operator()(ValueType v) const {
// ...
}
};
std::for_each (map.begin(), map.end(), DoLoopBody ());
Unfortunately the class DoLoopBody cannot be a local class, which is often highlighted as a disadvantage. However, I see this as an advantage in that the body of the loop can now be unit tested in isolation.