The following code shows what I currently have. It is an adapter for circular data-structures. The main function shows how it is used. This is all nice and fast but I really
If it were me, I'd have operator++
notice the terminal condition, and set c
to some sentinal value:
circulator(circ& c) : c(&c), start(&c) {}
circulator& operator++() { c = c->next; if(c==start) c=nullptr; return *this; }
Usage:
circulator begin{a}, end;
while(begin != end) {
begin++;
}
Note that this usage defines the end iterator as holding a nullptr, which means that you can't do this:
circulator end;
--end;