You might like to look at the circular buffer implementation in boost. I also have my own c++ code for circular. It is an iterator adaptor. Basically, it adapts an iterator to a circular iterator using mod function.