Nico Josuttis gave a talk recently that included an example and I wanted to explain what’s going on in this example, what the issue is, and what (if anything) is broken.
Mutating Through a Filter
by Barry Revzin
From the article:
As with a lot of my explanations, we have to start from the beginning.
The C++ iterator model has a number of iterator categories: input, forward, bidirectional, random access, and (since C++20) contiguous. This post only needs to consider the first two.
An input range (a range whose iterator is an input iterator) is a single-pass range. You can only ever call
begin()one time on it. You can’t have multiple different input iterators into the same range - incrementing one immediately invalidates any existing copies.
Add a CommentComments are closed.