Arno Schödl

Why Iterators Got It All Wrong — and what we should use instead

C++ iterators are broken by design. Their ambiguity creates subtle bugs with modern ranges. It's time for a safer, more explicit model.

Why Iterators Got It All Wrong — and what we should use instead
#1about 1 minute

The dual role of C++ iterators as elements and borders

C++ iterators, modeled after pointers, are used ambiguously to represent both specific elements and the borders between them.

#2about 1 minute

Writing cleaner code with C++ ranges

C++20 ranges simplify code by reducing the boilerplate of begin() and end() calls required with traditional iterator pairs.

#3about 4 minutes

Using range adapters for lazy transformations

Range adapters like transform allow for lazy evaluation, separating data projection from the search operation for more modular code.

#4about 2 minutes

How filter adapters create ambiguity for borders

The filter adapter demonstrates a flaw where mapping a border from a filtered range back to the original range is ambiguous.

#5about 5 minutes

The core problem with the reverse adapter

The reverse adapter proves that a single .base() method cannot correctly map both elements and borders back to the original range.

#6about 3 minutes

A formal solution with element and border concepts

The fundamental iterator flaw can be solved by introducing two distinct concepts: 'border' for positions between items and 'element' for the items themselves.

#7about 4 minutes

Improving algorithms with nullable elements and better names

Further improvements include making element types nullable to handle 'not found' cases cleanly and using more descriptive algorithm names like binary_find.

#8about 2 minutes

Conclusion and the think-cell range library

The think-cell C++ range library implements concepts like nullable elements and refined algorithms to address the inherent flaws in standard iterators.

#9about 4 minutes

Q&A on iterator invalidation and border types

The speaker addresses audience questions regarding how the border and element distinction interacts with container iterator invalidation and mathematical open or closed intervals.

Related jobs
Jobs that call for the skills explored in this talk.

Featured Partners

Related Articles

View all articles
BR
Benjamin Ruschin
What Developers Really Need to Create Great Code Demos
Every developer on earth has, at some point, had another developer to thank for a breakthrough, a success, an aha moment they wouldn’t have had without coming across that blog post, that open-source contribution, that reply on socials or that humble ...
What Developers Really Need to Create Great Code Demos
CH
Chris Heilmann
All the videos of Halfstack London 2024!
Last month was Halfstack London, a conference about the web, JavaScript and half a dozen other things. We were there to deliver a talk, but also to record all the sessions and we're happy to share them with you. It took a bit as we had to wait for th...
All the videos of Halfstack London 2024!
BB
Benedikt Bischof
How we Build The Software of Tomorrow
Welcome to this issue of the WeAreDevelopers Live Talk series. This article recaps an interesting talk by Thomas Dohmke who introduced us to the future of AI – coding.This is how Thomas describes himself:I am the CEO of GitHub and drive the company’s...
How we Build The Software of Tomorrow

From learning to earning

Jobs that call for the skills explored in this talk.

Rust and GoLang

Rust and GoLang

NHe4a GmbH
Karlsruhe, Germany

Remote
55-65K
Intermediate
Senior
Go
Rust
Software Architect

Software Architect

iteratec GmbH
Frankfurt am Main, Germany

Remote
Java
Azure
React
Spring
+10
Softwareentwickler

Softwareentwickler

iteratec GmbH
Frankfurt am Main, Germany

Azure
Google Cloud Platform
Amazon Web Services (AWS)