Yeah almost, except that since 'it' is first assigned 'start', and then the loop continuation 'it != start' is evaluated and found to be false, the code in the loop will never be executed.
I find that the only valid way to visit every item in a ring-list is to use both an if-statement and a do-while loop. i.e.You most certainly cannot use a for_each as I'm sure everybody is aware of already.Code:typedef circular_iterator<std::list<int>::iterator> cilit; if (!lst.empty()) { cilit start = circular_begin(lst), it = start; do { cout << *it << endl; } while (++it != start); }
Now, as you can guess, I've definitely written one of these before!