#ifndef ISTREAM_ITERATOR_DATEH #define ISTREAM_ITERATOR_DATEH #include #include #include "date.h" using namespace std; class istream_iterator_date: public iterator { istream *ist; bool ok; //true if this iterator has a healthy istream date d; //the date read most recently from the file void read() { if (ok) { ok = *ist >> d; //ok=operator>>(*ist,d).operator void *(); } } public: istream_iterator_date(istream& initial_is) : ist(&initial_is), ok(true) {read();} istream_iterator_date(): ist(0), ok(false) {} const date& operator*() const {return d;} const date *operator->() const {return &**this;} istream_iterator_date& operator++() {read(); return *this;} friend bool operator==(const istream_iterator_date& it1, const istream_iterator_date& it2) { return it1.ok == it2.ok && (!it1.ok || it1.ist == it2.ist); } }; inline const istream_iterator_date operator++(istream_iterator_date& it, int) { const istream_iterator_date old = it; ++it; return old; } inline bool operator!=(const istream_iterator_date& it1, const istream_iterator_date& it2) { return !(it1 == it2); } #endif