#ifndef ITERATOR_H #define ITERATOR_H 1 #include /** A counting output iterator. */ class CountingOutputIterator { public: explicit CountingOutputIterator(size_t& count) : m_count(count) { m_count = 0; } CountingOutputIterator& operator++() { ++m_count; return *this; } CountingOutputIterator& operator*() { return *this; } template CountingOutputIterator& operator=(const T&) { return *this; } private: size_t& m_count; }; /** An output stream iterator, like ostream_iterator, that outputs the * a delimiter before and after the item. */ template > class affix_ostream_iterator : public std::iterator { public: typedef charT char_type; typedef traits traits_type; typedef std::basic_ostream ostream_type; typedef void value_type; affix_ostream_iterator(ostream_type& s, charT const *prefix, charT const *suffix = NULL) : os(&s), prefix(prefix), suffix(suffix) {} affix_ostream_iterator& operator =(T const &item) { if (prefix != NULL) *os << prefix; *os << item; if (suffix != NULL) *os << suffix; return *this; } affix_ostream_iterator &operator*() { return *this; } affix_ostream_iterator &operator++() { return *this; } affix_ostream_iterator &operator++(int) { return *this; } private: std::basic_ostream *os; charT const* prefix; charT const* suffix; }; /** Traits of an output iterator. */ template struct output_iterator_traits { typedef typename OutputIterator::value_type value_type; }; /** Traits of a back_insert_iterator. */ template struct output_iterator_traits< std::back_insert_iterator > { typedef typename Container::value_type value_type; }; /** Traits of an ostream_iterator. */ template struct output_iterator_traits< std::ostream_iterator > { typedef T value_type; }; /** Traits of an affix_ostream_iterator. */ template struct output_iterator_traits< affix_ostream_iterator > { typedef T value_type; }; #endif