[MUC++] Tristan Brindle - Iteration Revisited
Channel: MUCplusplus
Date: 29/10/2023

“Safety” is the word on everyone’s lips at the moment. Unfortunately for C++ programmers, one of our most fundamental abstractions — iterators — are fraught with danger. Prone to out-of-bounds memory accesses, unexpected invalidation and dangling, iterators are a UB minefield in which even experts can find themselves in trouble.

Fortunately there is something we can do about it.  

In this talk we’ll look at an alternative, safer abstraction for iterating over sequences and introduce Flux, a new C++20 library implementing these ideas. We’ll see how Flux retains all of the power and flexibility of the existing STL, but greatly reduces the potential for UB through careful design and implementation choices — all while offering compatibility with existing code. We’ll also take a look at performance and examine the cost of universal bounds checking. Spoiler: it’s probably a lot less than you’d think. In fact, we’ll see how Flux code can actually outperform equivalent C++20 Ranges code in some common situations. Finally, we’ll take a quick look at some other quality-of-life improvements that Flux brings.

If you’re interested in the STL and the ranges and algorithms in C++20 and are looking for an easy-to-use way of making your codebase more resilient, then this is the talk for you.