Create iterators with a cycle

Hi, i want to create several iterators with a cycle, in this case a "for".

For example, i have a vector of "n" size and what i want to do is create an iterator for each of the values like it1,it2,it3...itn.

Hope you can help me thnks ;D
1
2
3
4
5
6
7
8
std::vector<T> v;
typedef std::vector<T>::iterator i_t;
std::vector<i_t> v2;
v2.reserve(v.size()+1);
v2.push_back(v.begin());
while (v2.back()!=v.end())
    v2.push_back(v2.back()+1);
v2.pop_back();
That would be one way. Why do you want this, though?
+1 to helios, and I must say that vectors use random access iterators, so inferring an iterator for a particular item is trivial: Add the item's position to the vector's begin() iterator. Therefore, I believe that storing those is just a waste of memory.
Topic archived. No new replies allowed.