#ifndef OPP_ITERATOR_H #define OPP_ITERATOR_H namespace opp { template class back_insert_iterator { protected: CT * co; public: back_insert_iterator (CT & c) : co(&c) {} back_insert_iterator & operator= (const CT::element_type & t) { co->push_back(t); return *this; } back_insert_iterator & operator= (CT::element_type && t) { co->push_back(t); return *this; } back_insert_iterator & operator* (void) { return *this; } back_insert_iterator & operator++ (void) { return *this; } back_insert_iterator operator++ (int) { return *this; } }; template class front_insert_iterator { protected: CT * co; public: front_insert_iterator (CT & c) : co(&c) {} front_insert_iterator & operator= (const CT::element_type & t) { co->push_front(t); return *this; } front_insert_iterator & operator= (CT::element_type && t) { co->push_front(t); return *this; } front_insert_iterator & operator* (void) { return *this; } front_insert_iterator & operator++ (void) { return *this; } front_insert_iterator operator++ (int) { return *this; } }; template class insert_iterator { protected: CT * co; CT::iterator_type ci; public: insert_iterator (CT & c, const CT::iterator_type & i) : co(&c), ci(i) {} insert_iterator & operator= (const CT::element_type & t) { ci = co->insert(ci, t); ++ci; return *this; } insert_iterator & operator= (CT::element_type && t) { ci = co->insert(ci, t); ++ci; return *this; } insert_iterator & operator* (void) { return *this; } insert_iterator & operator++ (void) { return *this; } insert_iterator operator++ (int) { return *this; } }; template class ostream_iterator { protected: ostream & stream; const char * str; public: ostream_iterator(ostream & stream_, const char * str_) : stream(stream_), str(str_) {} ostream_iterator & operator= (const T & t) { stream << t; if (str) stream << str; return *this; } ostream_iterator & operator= (T && t) { stream << t; if (str) stream << str; return *this; } ostream_iterator & operator* (void) { return *this; } ostream_iterator & operator++ (void) { return *this; } ostream_iterator operator++ (int) { return *this; } }; template front_insert_iterator front_inserter (CT & c) { return front_insert_iterator(c); } template back_insert_iterator back_inserter (CT & c) { return back_insert_iterator(c); } template insert_iterator inserter (CT & c, const CT::iterator_type & i) { return insert_iterator(c, i); } template CT next(CT it, int n = 1) { while (n > 0) { it++; n--; } return it; } template CT prev(CT it, int n = 1) { while (n > 0) { it--; n--; } return it; } }