Writing a Custom General-Purpose Algorithm
Explore how to create a custom general-purpose algorithm called flatzip that combines two input ranges by alternating their elements into a new range using iterators. Understand iterator abstraction and apply this to various container types including vectors and circular buffers. By the end, you'll grasp the mechanics of writing versatile algorithms that work with different containers and iterator types.
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 ...