#ifndef T_ITERATOTH #define T_ITERATOTH #include //for exit #include #include using namespace std; template class t_iterator: public iterator { bool at_end; //true if we have reached end of range T t; public: t_iterator(): at_end(true) {} t_iterator(const T& initial_t): at_end(false), t(initial_t) {} const T& operator*() const { if (at_end) { cerr << "dereference exhausted t_iterator\n"; exit(EXIT_FAILURE); } return t; } t_iterator& operator++() { if (at_end) { cerr << "increment exhausted t_iterator\n"; exit(EXIT_FAILURE); } typedef numeric_limits limits; //for convenience if (limits::is_specialized && t == limits::max()) { at_end = true; } else { ++t; } return *this; } friend bool operator==(const t_iterator& it1, const t_iterator& it2) { return it1.at_end == it2.at_end && (it1.at_end || it1.t == it2.t); } //etc. }; //etc. #endif