O'Reilly logo

Design Patterns in Modern C++: Reusable Approaches for Object-Oriented Software Design by Dmitri Nesteruk

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

© Dmitri Nesteruk 2018

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

16. Iterator

Dmitri Nesteruk

(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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required