STL iterators



 DEVELOP > c-Plus-Plus > STL iterators

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
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
.


  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER