Search⌘ K

Use Reverse Iterator Adapters to Iterate Backward

Explore how to implement and use reverse iterator adapters to traverse C++ STL containers backward. Understand bidirectional iterators and adapt iteration techniques for both STL containers and primitive arrays to print elements in reverse order.

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