| Topic: |
DEVELOP > c-Plus-Plus |
| User: |
"Rusty" |
| Date: |
27 Nov 2003 03:24:32 PM |
| Object: |
STL iterators |
Is there a simple way to increment (or decrement) a
std::vector::iterator and have it wrap to the other end once it passes
the beginning/end?
.
|
|
| User: "Cy Edmunds" |
|
| Title: Re: STL iterators |
27 Nov 2003 05:01:05 PM |
|
|
"Rusty" <russR-E-M-O-V-Eford@shaw.ca> wrote in message
news:2rqcsv0d6kquabkd1bj4s0l82hj8q27eis@4ax.com...
Is there a simple way to increment (or decrement) a
std::vector::iterator and have it wrap to the other end once it passes
the beginning/end?
No. But it wouldn't be very hard to write your own iterator that works this
way:
template <typename T>
class modular_iterator
{
private:
std::vector<T>::iterator m_first;
std::vector<T>::iterator m_last;
std::vector<T>::iterator m_this;
public:
modular_iterator(std::vector<T> &a) : m_first(a.begin()),
m_last(a.end()); m_this(a.begin()) {}
T &operator * () {return *m_this;}
// etc. for all other iterator functions
};
--
Cy
http://home.rochester.rr.com/cyhome/
.
|
|
|
|
| User: "Matt S Trentini" |
|
| Title: Re: STL iterators |
28 Nov 2003 06:42:00 PM |
|
|
Heya Rusty,
Rusty wrote:
Is there a simple way to increment (or decrement) a
std::vector::iterator and have it wrap to the other end once it passes
the beginning/end?
There's no standard way but there is a cycle_iterator in the boost
sandbox which looks like what you want:
http://groups.yahoo.com/group/boost/files/cycle_iterator/
Cheers,
Matt
.
|
|
|
|

|
Related Articles |
|
|