© Dmitri Nesteruk 2018
Dmitri NesterukDesign Patterns in Modern C++https://doi.org/10.1007/978-1-4842-3603-1_16

16. Iterator

Dmitri Nesteruk1 
(1)
St. Petersburg, Russia
 

Any time you start working with complicated data structures, you encounter the problem of traversal . This can be handled in different ways, but the most common way of traversing, say, a vector is using something called an iterator.

An iterator is, quite simply, an object that can point to an element of a collection and also knows how to move to the next element in the collection. As such, it is only required to implement the ++ operator and the != operator (so you can compare two iterators and check if they point to the same thing). That’s it.

The C++ Standard Library makes heavy ...

Get Design Patterns in Modern C++: Reusable Approaches for Object-Oriented Software Design now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.