T
Tim H
I'm working on a class that wraps a vector. In fact, it behaves very
much like a vector. I've read it's "bad" to subclass vector, since it
is not intended for that use. So I am wrapping it. I have a lot of
simple pass-thru methods, which is fine.
Where it all breaks down is iterators. The underlying vector is
storing annotated data that the caller does not need to see. Think of
it this way:
template <class T>
class helper { ... };
template <class T>
class vector_wrapper {
....
vector< helper<T> > real_vector;
....
};
Making vector_wrapper iterate in all the same ways as a regular vector
is just falling down. I find myself hacking and slashing to get const
iterators to actually be const and reverse iterators to work, etc.
Does anyone have an example of a class that wraps vector and provides
full iterability?
Tim
much like a vector. I've read it's "bad" to subclass vector, since it
is not intended for that use. So I am wrapping it. I have a lot of
simple pass-thru methods, which is fine.
Where it all breaks down is iterators. The underlying vector is
storing annotated data that the caller does not need to see. Think of
it this way:
template <class T>
class helper { ... };
template <class T>
class vector_wrapper {
....
vector< helper<T> > real_vector;
....
};
Making vector_wrapper iterate in all the same ways as a regular vector
is just falling down. I find myself hacking and slashing to get const
iterators to actually be const and reverse iterators to work, etc.
Does anyone have an example of a class that wraps vector and provides
full iterability?
Tim