
I imagine your line-by-line reading iterator would look something like (PSEUDO-CODE!!!):
class line_by_line_iterator { buffer_t& buffer;
public: const buffer_t& operator*() const { return buffer; } void operator++() { format_specific_read_one_line_into(buffer); } };
I'd do it using iterator_facade.
A case that this fails to manage efficiently is when your format-specific implementation has an efficient way to skip forward without actually decoding. This is not something that I've ever had to worry about, but I think you could do it easily enough by adding a flag and doing the read lazily in operator*.
you mean pass a boolean into operator*?
Surely not, as the signature of an overloaded operator is fixed :) I think Phil means rather than do the read in operator++, just set a flag in operator++ that the read should be done, and actually do it in operator* (which then clears the flag). Then if someone calls operator++ again without calling operator* (which you can detect by the flag being set in operator++), you can do a skip in operator++, and thus avoid decoding the line you didn't need. Regards, Nate