cpp_weekly
cpp_weekly copied to clipboard
How (and why) to write a custom iterator class
Channel "C++Weekly"
Topics
Walk through how to write a proper and complete iterator.
I've only recently started doing this to adapt custom data structures (e.g. a special tree structure) or existing interfaces (e.g. it just provides stuff like getNumElements()
and getElement(i)
, or provides its own iterator-like API) to use with standard algorithms and with ranges. It was easier than I thought it would be, why did it take me so long? Would be great for everyone to know about doing this, and to go over all the aspects that make an implementation really complete (beyond just the minimum to work in basic circumstances) and to what conventions to use (similar to standard library iterators.)
Length
Depends on how much you want to talk about it, but could be quite short if desired.