"Integration of the Standard Template Library and the Microsoft Foundation Class" - читать интересную книгу автора (Wolfgang Paul, Song Yang)
2.4.4.2 CArchive_input_iterator
The loop to read a stroke must terminate after all of the points for that stroke have been read. This is not at the end of the input stream. We will need to pass to the copy algorithm a CArchive_input_iterator that represents the current file position as the first argument, and a CArchive_input_iterator that represents the position at which the copy operator should stop. If we were copying from a standard array, the copy call would look something like this:
copy(start, start+n, destination);
Therefore, we overload the + operator so that a CArchive_input_iterator plus an int will result in a CArchive_input_iterator object that can be used by the equality operator called by the copy algorithm to terminate the loop.
In istream_iterator the data value is extracted from the istream when the iterator object is first created and whenever the ++ operator is called. The dereferencing operator (*) then retrieves the saved value. Since we do not want to extract an object from the CArchive once the specified number of objects have been retrieved, we set a flag to indicate the need to retrieve a new object, and have the actual extraction performed by the * operator. The resulting implementation of CArchive_input_iterator is as follows:
template ‹class T›
class CArchive_input_iterator: std::iterator‹std::input_iterator_t ag, T, ptrdiff_t› {