I have a class which opens text files and returns roughly equally-sized chunks of std::string each time a public method next() is called, like so:
Code:
int chunks = 32;
Read summary("path/to/file.txt", chunks);
for(int i = 0; i < chunks; ++i)
{
summary.next(); // hand over to thread...
}
I thought it would be neater if I could do:
Code:
Read summary("path/to/file.txt", chunks);
for(auto chunk : summary)
{
*chunk;
}
Is is possible to implement something like that? And would I need to inherit from e.g. std::iterator<input_iterator_tag, std::string> (adapting all methods) for the foreach loop to work, or can I just implement from scratch the methods that I want to support (increment, deference, compare) and be done with it?