Software libraries rely increasingly on iterators to provide generic traversal of data structures. These iterators can be represented either as objects that maintain state or as programs that suspend and resume control. This paper addresses two problems that remain in the use of iterators today: The first problem is that iterators represented as state-saving objects in languages such as C++ or Java typically have logic that is much more complicated than control?based iterators. This paper presents a program structuring technique that allows object?based iterators to be implemented with the same clarity as control?based iterators. The second problem is that the usual implementations of control?based iterators are not sufficiently efficient for high-performance applications. This paper presents a code optimization technique that can be applied to control?based iteration to produce efficient natural loops at the machine code level. Combined, these two results allow iterators for complex ...
Stephen M. Watt