Robert Ramey wrote:
I like these a lot. Could you add a few more comments?
I'm not sure what you mean by "keeps track of wrap" or NOT.
Maybe some information about what difference means. That is when iterator loops around behind the other one - does this make the difference negative? Is this what is meant by wrap?
Ideally, I would like to see these zipped up along with a simple document and added to the vault.
Robert Ramey
I have uploaded cycle_iterator.hpp, cycle_iterator2.hpp, cycle_iterator.txt, and Ring.H to vault under 'iterators'. Here is cycle_iterator.txt: There are 2 kinds of cyclic iterator adaptors here. cycle_iterator keeps track of an absolute position. Even though a dereference into the container will be treated modulo the size of the container, when comparing iterators we will keep track (with the wrap member) how many times the iterator 'wrapped around'. That is, we have the concept of a 'realposition' offset_t realposition () const { return position + wrap * size; } The effect is that the distance between two iterators can be greater than the size of the container. cycle_iterator2 has different semantics, it does not track this wraparound. One effect of this is you will need to be careful if you wish to access all the elements in the container, since the iterator pointing to the 'begin' and that pointing to the 'end' in typical STL usage may be the same. Ring2.H is a (not fully cleaned up) example of usage. A Ring is a vector-like structure (std::vector by default) whose iterators are cycle_iterator.