Writing Our Own Range Adaptor

Learn to implement a custom range adaptor in this lesson.

We'll cover the following

The standard library contains a series of range adaptors that can be used for solving many different tasks. More are being added in newer versions of the standard. However, there can be situations when we’d like to create our own range adaptor to use with others from the range library. This is not actually a trivial task. For this reason, in this final lesson of the section, we’ll explore the steps we need to follow to write such a range adaptor.

The step_view range adaptor

For this purpose, we’ll consider a range adaptor that takes every Nth element of a range and skips the others. We’ll call this adaptor step_view. We can use it to write code as follows:

Get hands-on with 1200+ tech skills courses.