I need to wrap a vector iterator, but I don't like the idea of rewriting it from scratch. And I cannot subclass it, since the vector iterator does not seem cross-platform. At least gnu and ibm look different.
I want to do the following:
class MyContainer { vector<double> data; vector<int> indices; iterator begin() { return my_iterator(data, indices.begin()); } iterator end() { return my_iterator(data, indices.end()); } } MyContainer cont;
If the index vector contains integer positions in the data vector. It is assumed that the data will be much larger than the indexes.
So, I need an iterator that can go through indices in any direction, such as a normal vector iterator, with one exception: it must return the value of the data vector when the value is accessed. eg:.
for(MyContainer::iterator it = cont.begin(); it != cont.end(); it++) { cout << *it << endl;
Basically, it should look like a regular collection for the std world. You can repeat it in any direction you want, you can sort it, run unique, find_if, etc.
any simple solution?
source share