You have a quick question about what would be the best way to implement iterators in the following:
Let's say I have a template “List” of the base class and two subclasses “ListImpl1” and “ListImpl2”. The basic requirement of the base class must be iterable, i.e. I can do:
for(List<T>::iterator it = list->begin(); it != list->end(); it++){
...
}
I also want to allow the addition of an iterator, for example:
for(List<T>::iterator it = list->begin()+5; it != list->end(); it++){
...
}
Thus, the problem is that the implementation of the iterator for ListImpl1 will be different from the implementation for ListImpl2. I got around this using the ListIterator wrapper containing a pointer to ListIteratorImpl with subclasses of ListIteratorImpl2 and ListIteratorImpl2, but it all gets pretty messy, especially when you need to implement operator + in ListIterator.
Any thoughts on a better design to get around these issues?