14ITERATORS

Say “friend” and enter.—J.R.R. Tolkein, The Lord of the Rings

Image

Iterators are the STL component that provides the interface between containers and algorithms to manipulate them. An iterator is an interface to a type that knows how to traverse a particular sequence and exposes simple, pointer-like operations to elements.

Every iterator supports at least the following operations:

  • Access the current element (operator*) for reading and/or writing
  • Go to the next element (operator++)
  • Copy construct

Iterators are categorized based on which additional operations they support. These categories determine which algorithms are available and what ...

Get C++ Crash Course 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.