A simple answer to a complex question: Yes that is what iterators are here for after all. You can build an enumerator that would effectively return all of N or the fibonacci series or the faculty function. How much of that series is in fact consumed depends on the code the user runs (and the data type involved of course as you might hit a limit there).
The following site deals with an enumerator in C# but applies also to C++:
http://thoughtfulcode.wordpress.com/2011/01/14/ienumerable-is-lazy-and-thats-cool/[
^]
Modification:
XTAL256 wrote:
there would be some code that would get a batch of data and cache it, then when more data is required it gets the next batch
I actually missed this part in your question and want to elaborate a bit on the possibilities enumerators give you: Since you have total control over what the enumerators do internally you can also implement some kind of paging mechanism that will fetch batches of data as you put it. As long as you understand and implement all of the IEmumerable interface all of this can be transparent to the user of your code. Why did I say "can be transparent to the user"?
It means you can hide all the "behind the curtain" details from the user or else give him some control by defining some constructors for your IEnumerable implementing class that let him specify fetched batch size etc.
End Modification
Best Regards,
Manfred