#ifndef POINTERH #define POINTERH #include #include //for classes iterator and input_iterator_tag using namespace std; class pointer: public iterator { istream *istr; bool ok; //true if not yet at end of file int i; void read() {if (ok) {ok = *istr >> i;}} public: pointer(istream& initial_istr): istr(&initial_istr), ok(true) {read();} pointer(): istr(0), ok(false) {} const int operator*() const {return i;} pointer& operator++() {read(); return *this;} //prefix friend bool operator==(const pointer& p1, const pointer& p2) { return p1.ok == p2.ok && (!p1.ok || p1.istr == p2.istr); } }; inline const pointer operator++(pointer& p, int) //postfix { const pointer old = p; ++p; //p.operator++() return p; } inline bool operator!=(const pointer& p1, const pointer& p2) { return !(p1 == p2); } #endif