iterator.hpp
来自「Boost provides free peer-reviewed portab」· HPP 代码 · 共 1,437 行 · 第 1/4 页
HPP
1,437 行
} BOOST_UBLAS_INLINE friend reverse_iterator_base operator + (difference_type n, const reverse_iterator_base &it) { reverse_iterator_base tmp (it); return tmp += n; } BOOST_UBLAS_INLINE friend reverse_iterator_base operator - (const reverse_iterator_base &it, difference_type n) { reverse_iterator_base tmp (it); return tmp -= n; } BOOST_UBLAS_INLINE friend difference_type operator - (const reverse_iterator_base &it1, const reverse_iterator_base &it2) { return it2.base () - it1.base (); } BOOST_UBLAS_INLINE const container_type &operator () () const { return this->base () (); } BOOST_UBLAS_INLINE size_type index () const { iterator_type tmp (this->base ()); return (-- tmp).index (); } }; /** \brief 1st base class of all matrix reverse iterators. (non-MSVC version) * * \param I the derived iterator type * * The reverse iterator implements a bidirectional iterator * reversing the elements of the underlying iterator. It * implements most operators of a random access iterator. * * uBLAS extension: it.index1(), it.index2() and access to * the dual iterator via begin(), end(), rbegin(), rend() */ // Renamed this class from reverse_iterator1 to get // typedef reverse_iterator1<...> reverse_iterator1 // working. Thanks to Gabriel Dos Reis for explaining this. template <class I> class reverse_iterator_base1: public std::reverse_iterator<I> { public: typedef typename I::container_type container_type; typedef typename container_type::size_type size_type; typedef typename I::difference_type difference_type; typedef I iterator_type; typedef typename I::dual_iterator_type dual_iterator_type; typedef typename I::dual_reverse_iterator_type dual_reverse_iterator_type; // Construction and destruction BOOST_UBLAS_INLINE reverse_iterator_base1 (): std::reverse_iterator<iterator_type> () {} BOOST_UBLAS_INLINE reverse_iterator_base1 (const iterator_type &it): std::reverse_iterator<iterator_type> (it) {} // Arithmetic BOOST_UBLAS_INLINE reverse_iterator_base1 &operator ++ () { return *this = -- this->base (); } BOOST_UBLAS_INLINE reverse_iterator_base1 operator ++ (int) { reverse_iterator_base1 tmp (*this); *this = -- this->base (); return tmp; } BOOST_UBLAS_INLINE reverse_iterator_base1 &operator -- () { return *this = ++ this->base (); } BOOST_UBLAS_INLINE reverse_iterator_base1 operator -- (int) { reverse_iterator_base1 tmp (*this); *this = ++ this->base (); return tmp; } BOOST_UBLAS_INLINE reverse_iterator_base1 &operator += (difference_type n) { return *this = this->base () - n; } BOOST_UBLAS_INLINE reverse_iterator_base1 &operator -= (difference_type n) { return *this = this->base () + n; } BOOST_UBLAS_INLINE friend reverse_iterator_base1 operator + (const reverse_iterator_base1 &it, difference_type n) { reverse_iterator_base1 tmp (it); return tmp += n; } BOOST_UBLAS_INLINE friend reverse_iterator_base1 operator + (difference_type n, const reverse_iterator_base1 &it) { reverse_iterator_base1 tmp (it); return tmp += n; } BOOST_UBLAS_INLINE friend reverse_iterator_base1 operator - (const reverse_iterator_base1 &it, difference_type n) { reverse_iterator_base1 tmp (it); return tmp -= n; } BOOST_UBLAS_INLINE friend difference_type operator - (const reverse_iterator_base1 &it1, const reverse_iterator_base1 &it2) { return it2.base () - it1.base (); } BOOST_UBLAS_INLINE const container_type &operator () () const { return this->base () (); } BOOST_UBLAS_INLINE size_type index1 () const { iterator_type tmp (this->base ()); return (-- tmp).index1 (); } BOOST_UBLAS_INLINE size_type index2 () const { iterator_type tmp (this->base ()); return (-- tmp).index2 (); } BOOST_UBLAS_INLINE dual_iterator_type begin () const { iterator_type tmp (this->base ()); return (-- tmp).begin (); } BOOST_UBLAS_INLINE dual_iterator_type end () const { iterator_type tmp (this->base ()); return (-- tmp).end (); } BOOST_UBLAS_INLINE dual_reverse_iterator_type rbegin () const { return dual_reverse_iterator_type (end ()); } BOOST_UBLAS_INLINE dual_reverse_iterator_type rend () const { return dual_reverse_iterator_type (begin ()); } }; /** \brief 2nd base class of all matrix reverse iterators. (non-MSVC version) * * \param I the derived iterator type * * The reverse iterator implements a bidirectional iterator * reversing the elements of the underlying iterator. It * implements most operators of a random access iterator. * * uBLAS extension: it.index1(), it.index2() and access to * the dual iterator via begin(), end(), rbegin(), rend() * * Note: this type is _identical_ to reverse_iterator_base1 */ // Renamed this class from reverse_iterator2 to get // typedef reverse_iterator2<...> reverse_iterator2 // working. Thanks to Gabriel Dos Reis for explaining this. template <class I> class reverse_iterator_base2: public std::reverse_iterator<I> { public: typedef typename I::container_type container_type; typedef typename container_type::size_type size_type; typedef typename I::difference_type difference_type; typedef I iterator_type; typedef typename I::dual_iterator_type dual_iterator_type; typedef typename I::dual_reverse_iterator_type dual_reverse_iterator_type; // Construction and destruction BOOST_UBLAS_INLINE reverse_iterator_base2 (): std::reverse_iterator<iterator_type> () {} BOOST_UBLAS_INLINE reverse_iterator_base2 (const iterator_type &it): std::reverse_iterator<iterator_type> (it) {} // Arithmetic BOOST_UBLAS_INLINE reverse_iterator_base2 &operator ++ () { return *this = -- this->base (); } BOOST_UBLAS_INLINE reverse_iterator_base2 operator ++ (int) { reverse_iterator_base2 tmp (*this); *this = -- this->base (); return tmp; } BOOST_UBLAS_INLINE reverse_iterator_base2 &operator -- () { return *this = ++ this->base (); } BOOST_UBLAS_INLINE reverse_iterator_base2 operator -- (int) { reverse_iterator_base2 tmp (*this); *this = ++ this->base (); return tmp; } BOOST_UBLAS_INLINE reverse_iterator_base2 &operator += (difference_type n) { return *this = this->base () - n; } BOOST_UBLAS_INLINE reverse_iterator_base2 &operator -= (difference_type n) { return *this = this->base () + n; } BOOST_UBLAS_INLINE friend reverse_iterator_base2 operator + (const reverse_iterator_base2 &it, difference_type n) { reverse_iterator_base2 tmp (it); return tmp += n; } BOOST_UBLAS_INLINE friend reverse_iterator_base2 operator + (difference_type n, const reverse_iterator_base2 &it) { reverse_iterator_base2 tmp (it); return tmp += n; } BOOST_UBLAS_INLINE friend reverse_iterator_base2 operator - (const reverse_iterator_base2 &it, difference_type n) { reverse_iterator_base2 tmp (it); return tmp -= n; } BOOST_UBLAS_INLINE friend difference_type operator - (const reverse_iterator_base2 &it1, const reverse_iterator_base2 &it2) { return it2.base () - it1.base (); } BOOST_UBLAS_INLINE const container_type &operator () () const { return this->base () (); } BOOST_UBLAS_INLINE size_type index1 () const { iterator_type tmp (this->base ()); return (-- tmp).index1 (); } BOOST_UBLAS_INLINE size_type index2 () const { iterator_type tmp (this->base ()); return (-- tmp).index2 (); } BOOST_UBLAS_INLINE dual_iterator_type begin () const { iterator_type tmp (this->base ()); return (-- tmp).begin (); } BOOST_UBLAS_INLINE dual_iterator_type end () const { iterator_type tmp (this->base ()); return (-- tmp).end (); } BOOST_UBLAS_INLINE dual_reverse_iterator_type rbegin () const { return dual_reverse_iterator_type (end ()); } BOOST_UBLAS_INLINE dual_reverse_iterator_type rend () const { return dual_reverse_iterator_type (begin ()); } }; /** \brief A class implementing an indexed random access iterator. * * \param C the (mutable) container type * \param IC the iterator category * * This class implements a random access iterator. The current * position is stored as the unsigned integer it_ and the * values are accessed via operator()(it_) of the container. * * uBLAS extension: index() */ template<class C, class IC> class indexed_iterator: public container_reference<C>, public random_access_iterator_base<IC, indexed_iterator<C, IC>, typename C::value_type, typename C::difference_type> { public: typedef C container_type; typedef IC iterator_category; typedef typename container_type::size_type size_type; typedef typename container_type::difference_type difference_type; typedef typename container_type::value_type value_type; typedef typename container_type::reference reference; // Construction and destruction BOOST_UBLAS_INLINE indexed_iterator (): container_reference<container_type> (), it_ () {} BOOST_UBLAS_INLINE indexed_iterator (container_type &c, size_type it): container_reference<container_type> (c), it_ (it) {} // Arithmetic BOOST_UBLAS_INLINE indexed_iterator &operator ++ () { ++ it_; return *this; } BOOST_UBLAS_INLINE indexed_iterator &operator -- () { -- it_; return *this; } BOOST_UBLAS_INLINE indexed_iterator &operator += (difference_type n) { it_ += n; return *this; } BOOST_UBLAS_INLINE indexed_iterator &operator -= (difference_type n) { it_ -= n; return *this; } BOOST_UBLAS_INLINE difference_type operator - (const indexed_iterator &it) const { BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); return it_ - it.it_; } // Dereference BOOST_UBLAS_INLINE reference operator * () const { BOOST_UBLAS_CHECK (index () < (*this) ().size (), bad_index ()); return (*this) () (it_); } BOOST_UBLAS_INLINE reference operator [] (difference_type n) const { return *((*this) + n); } // Index BOOST_UBLAS_INLINE size_type index () const { return it_; } // Assignment BOOST_UBLAS_INLINE indexed_iterator &operator = (const indexed_iterator &it) { // FIX: ICC needs full qualification?! // assign (&it ()); container_reference<C>::assign (&it ()); it_ = it.it_; return *this; } // Comparison
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?