Submit Blog Login Last Submitted Blogs RSS Archive Contact  
Iterator
 
 
 
    Articles about Iterator
    The One True Iterator Declaration
    2007-04-20 15:29:51
    Continueing my rich history of bikeshed-quality blog posts, I proudly present: Three common ways to declare the iterators for iterating over a map: for ( map<string, string>::const_iterator it = map.begin(); it != map.end(); ++it ); Not bad. Unfortunately the line is kinda long, and the .end() function is queried over and over again. On the plus side, the iterator is nicely scoped (only valid within the loop) - but that doesn’t work with MSVC6. Oh well. map<string, string>::const_iterator it = map.begin(); map<string, string>::const_iterator end = map.end(); for ( ; it != end; ++it ); Not so cool. Both ‘it’ and ‘end’ outside of the scope of the loop. Might be what you want (for instance, the loop could break as soon as it (no pun intended) found a match. The super-sort for() line looks nice, and there are no unnecessary calls to map.end(). map<string, string>::const_iterator it, end = map.end(); for ( it = map.begin(); it != end
    By: FrogBlog
     
     
    TopBlogging
     
     
    TopBlogging
    TopBlogging.com TopBlogging.com
    eXTReMe Tracker