Writing a Custom General-Purpose Algorithm

Learn more about iterators and implementing the zipping algorithm in C++.

We'll cover the following

In the first lesson of this section, we saw why abstracting access to container elements with iterators is key for building general-purpose algorithms. However, it should be useful for us to practice writing such an algorithm because it can help us better understand the use of iterators. Therefore, in this lesson, we’ll write a general-purpose algorithm.

The zipping algorithm

The standard library features many such algorithms. One that is missing is a zipping algorithm. What zipping means is actually interpreted or understood differently by different people. For some, zipping means taking two or more input ranges and creating a new range with the elements from the input ranges intercalated. This is exemplified in the following diagram:

Get hands-on with 1400+ tech skills courses.