// arch-tag: dc0a48cf-c241-4480-b722-6e181cbd9fca /* * (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 strided_iterator_hpp #define strided_iterator_hpp #include #include namespace boost { template class strided_iterator : public boost::iterator_adaptor< strided_iterator, BaseIterator> { friend class iterator_core_access; public: typedef typename boost::iterator_adaptor,BaseIterator> super_t; typedef typename std::iterator_traits::difference_type difference_type; strided_iterator() {} explicit strided_iterator (BaseIterator _base, size_t _stride) : super_t (_base), stride (_stride) {} void increment() { this->base_reference() += stride; } void decrement() { this->base_reference() -= stride; } void advance(difference_type n) { this->base_reference() += n*stride; } difference_type distance_to(strided_iterator const& y) const { return (y.base_reference()-this->base_reference())/stride; } private: const int stride; }; template strided_iterator make_strided_iterator(BaseIterator const& begin, int stride) { return strided_iterator (begin, stride); } } // namespace boost #endif