Mutating Through a Filter -- Barry Revzin
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.

C language was defined to cover a large range of computer architectures, including many which would be considered museum relics today. It therefore takes a very conservative view of what is permitted, so that it remains possible to write C programs for those ancient systems. (Which weren’t quite so ancient at the time.)
Event-driven applications, such as GUIs or servers, often apply the architecture pattern Reactor. A Reactor can accept multiple requests simultaneously and distribute them to different handlers.
Last time I showed a couple of questions about initialization. Try them
In a previous
Every year we run Pure Virtual C++: a free one-day virtual conference for the whole C++ community. Next month we’re doing it again!