Last Updated: May 22, 2026
Most C++ code uses iterators handed out by the standard library, but sometimes defining a new one is the better option. A linked-list-like data structure with no STL counterpart, a numeric range generator, a wrapper around an external data source: any of these benefit from exposing an iterator interface so that std::find, std::transform, range-based for, and the rest of the algorithm library work against them. This chapter covers what an iterator type actually has to provide, the trait machinery that ties it into the STL, the iterator categories and how to pick one, and a worked example of an iterator for a small singly-linked list.