Boost logo

Boost :

From: md656 (md656_at_[hidden])
Date: 2001-02-26 14:06:59


> I would like to iterate over a container again and again (a vector,
> list or set). I would like to simply increment the iterator all the
> time, without having to check if I reached the end().

 
Sounds like a pretty straightforward program to me. Why not just do it?

    template<class Iter> class Cyclic_iterator {
    public:
Cyclic_Iterator(Iter b, Iter e): begin(b), end(e), it(b) { }
Cyclic_Iterator& operator++() {
     ++it;
     if (it == end)
         it = begin;
     return *this;
        }

// and so on -- it's up to you to fill in the rest

    private:
        Iter begin, end, it;
    };

Mohammed


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk