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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.