/* * (C) Copyright Neal D. Becker (2004) * Permission to copy, use, modify, sell and distribute this software * is granted provided this copyright notice appears in all copies. * This software is provided "as is" without express or implied * warranty, and with no claim as to its suitability for any purpose. */ #ifndef zippy_iterator_H #define zippy_iterator_H #include #include // next #include //! Cont is a container type. It is a container of iterators. template class zippy_iterator : public boost::iterator_facade, typename std::iterator_traits::value_type, boost::forward_traversal_tag> { public: typedef typename Cont::value_type iter_t; typedef typename std::iterator_traits::value_type value_t; typedef typename Cont::iterator cit; explicit zippy_iterator (Cont c) : cont (c), cont_iter (cont.begin()) {} template zippy_iterator& operator= (const zippy_iterator& z) { cont = z.cont; cont_iter = boost::next (cont.begin(), std::distance (const_cast (z.cont.begin()), const_cast (z.cont_iter))); } template zippy_iterator (const zippy_iterator& z) : cont (z.cont), cont_iter (boost::next (cont.begin(), std::distance (const_cast (z.cont.begin()), const_cast (z.cont_iter)))) { } zippy_iterator (const zippy_iterator& z) : cont (z.cont), cont_iter (boost::next (cont.begin(), std::distance (const_cast (z.cont.begin()), const_cast (z.cont_iter)))) { } value_t& dereference() const { return **cont_iter; } void increment() { (*cont_iter)++; cont_iter++; if (cont_iter == cont.end()) cont_iter = cont.begin(); } bool equal (zippy_iterator const& other) const { return std::equal (cont.begin(), cont.end(), other.cont.begin()); } private: Cont cont; typename Cont::iterator cont_iter; }; template inline zippy_iterator make_zippy_iterator (Cont_t cont) { return zippy_iterator (cont); } #endif