...

/

The Concepts Ranges and Views

The Concepts Ranges and Views

Get a quick refresher on the concepts, 'ranges' and 'views'.

We'll cover the following...

I already presented the concepts ranges and views when discussing concepts. Consequently, here’s a brief refresher:

  • range: A range is a group of items that you can iterate over. It provides a begin iterator and an end sentinel. The containers of the STL are ranges.

  • view: A view is something that you apply on a range and performs some operation. A view does not own data, and its time complexity to copy, move, or assign is constant.

Press + to interact
std::vector<int> numbers = {1, 2, 3, 4, 5, 6};
auto results = numbers | std::views::filter([](int n){ return n % 2 == 0; })
| std::views::transform([](int n){ return n * 2; });

In this code ...