I am trying to implement a class that will allow me to iterate over STL-style objects without explicitly storing them in a container.
A simplified example of this might be, for example, a <Paragraph>::iteratorin a class that actually does not have a container with paragraphs, but instead has a variable <string> text. It's easy to create a member function that actually goes through a line by line and collect paragraphs, but it seems foolish to keep all this text again in some container so that I can inherit from iterators.
Also, the reason I named it <Paragraph>::iterator, unlike <string>::iterator, is because I might want to have a different type of iterator. For example, I could count the number of characters in each paragraph and have <int>::iterator.
I think my question is: is it appropriate to think in terms of iterators when there is no container?
thank
source
share