Use Reverse Iterator Adapters to Iterate Backward

Learn to use reverse iterator adapters to iterate backward.

We'll cover the following

A reverse iterator adapter is an abstraction that reverses the direction of an iterator class. It requires a bidirectional iteratorA bidirectional iterator is a type of iterator that allows traversal of elements in both forward and backward directions within a container..

How to do it

Most bidirectional containers in the STL include a reverse iterator adapter. Other containers, such as the primitive C-array, do not. Let’s look at some examples:

  • Let’s start with the printc() function we’ve used throughout this chapter:

Get hands-on with 1400+ tech skills courses.