📄 iterator.hpp
字号:
reverse_iterator_base2 (): std::reverse_iterator<iterator_type> () {} BOOST_UBLAS_INLINE reverse_iterator_base2 (const iterator_type &it): std::reverse_iterator<iterator_type> (it) {}#ifndef BOOST_UBLAS_NO_REVERSE_ITERATOR_OVERLOADS // Arithmetic BOOST_UBLAS_INLINE reverse_iterator_base2 &operator ++ () { // Comeau recommends... return *this = -- this->base (); } BOOST_UBLAS_INLINE reverse_iterator_base2 operator ++ (int) { // Comeau recommends... reverse_iterator_base2 tmp (*this); *this = -- this->base (); return tmp; } BOOST_UBLAS_INLINE reverse_iterator_base2 &operator -- () { // Comeau recommends... return *this = ++ this->base (); } BOOST_UBLAS_INLINE reverse_iterator_base2 operator -- (int) { // Comeau recommends... reverse_iterator_base2 tmp (*this); *this = ++ this->base (); return tmp; } BOOST_UBLAS_INLINE reverse_iterator_base2 &operator += (difference_type n) { // Comeau recommends... return *this = this->base () - n; } BOOST_UBLAS_INLINE reverse_iterator_base2 &operator -= (difference_type n) { // Comeau recommends... return *this = this->base () + n; }#endif#ifndef BOOST_UBLAS_NO_MEMBER_FRIENDS 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 (); }#endif BOOST_UBLAS_INLINE const container_type &operator () () const { // Comeau recommends... return this->base () (); } BOOST_UBLAS_INLINE size_type index1 () const { // Comeau recommends... iterator_type tmp (this->base ()); return (-- tmp).index1 (); } BOOST_UBLAS_INLINE size_type index2 () const { // Comeau recommends... iterator_type tmp (this->base ()); return (-- tmp).index2 (); } BOOST_UBLAS_INLINE dual_iterator_type begin () const { // Comeau recommends... iterator_type tmp (this->base ()); return (-- tmp).begin (); } BOOST_UBLAS_INLINE dual_iterator_type end () const { // Comeau recommends... 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 ()); } };#ifdef BOOST_UBLAS_NO_MEMBER_FRIENDS template<class I> BOOST_UBLAS_INLINE reverse_iterator_base2<I> operator + (const reverse_iterator_base2<I> &it, std::ptrdiff_t n) { reverse_iterator_base2<I> tmp (it); return tmp += n; } template<class I> BOOST_UBLAS_INLINE reverse_iterator_base2<I> operator + (std::ptrdiff_t n, const reverse_iterator_base2<I> &it) { reverse_iterator_base2<I> tmp (it); return tmp += n; } template<class I> BOOST_UBLAS_INLINE reverse_iterator_base2<I> operator - (const reverse_iterator_base2<I> &it, std::ptrdiff_t n) { reverse_iterator_base2<I> tmp (it); return tmp -= n; } template<class I> BOOST_UBLAS_INLINE std::ptrdiff_t operator - (const reverse_iterator_base2<I> &it1, const reverse_iterator_base2<I> &it2) { return it2.base () - it1.base (); }#endif#endif /** \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 BOOST_UBLAS_INLINE bool operator == (const indexed_iterator &it) const { BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); return it_ == it.it_; } BOOST_UBLAS_INLINE bool operator < (const indexed_iterator &it) const { BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); return it_ < it.it_; } private: size_type it_; };#ifdef BOOST_MSVC_STD_ITERATOR template<class C, class I> BOOST_UBLAS_INLINE indexed_iterator<C, I> operator ++ (const indexed_iterator<C, I> &it, int) { indexed_iterator<C, I> tmp (it); ++ tmp; return tmp; } template<class C, class I> BOOST_UBLAS_INLINE indexed_iterator<C, I> operator -- (const indexed_iterator<C, I> &it, int) { indexed_iterator<C, I> tmp (it); -- tmp; return tmp; } template<class C, class I> BOOST_UBLAS_INLINE indexed_iterator<C, I> operator + (const indexed_iterator<C, I> &it, std::ptrdiff_t n) { indexed_iterator<C, I> tmp (it); return tmp += n; } template<class C, class I> BOOST_UBLAS_INLINE indexed_iterator<C, I> operator + (std::ptrdiff_t n, const indexed_iterator<C, I> &it) { indexed_iterator<C, I> tmp (it); return tmp += n; } template<class C, class I> BOOST_UBLAS_INLINE indexed_iterator<C, I> operator - (const indexed_iterator<C, I> &it, std::ptrdiff_t n) { indexed_iterator<C, I> tmp (it); return tmp -= n; }#endif /** \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 \c it_ and the * values are accessed via \c operator()(it_) of the container. * * uBLAS extension: \c index() * * Note: there is an automatic conversion from * \c indexed_iterator to \c indexed_const_iterator */ template<class C, class IC> class indexed_const_iterator: public container_const_reference<C>, public random_access_iterator_base<IC, indexed_const_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::const_reference reference; typedef indexed_iterator<container_type, iterator_category> iterator_type; // Construction and destruction BOOST_UBLAS_INLINE indexed_const_iterator (): container_const_reference<container_type> (), it_ () {} BOOST_UBLAS_INLINE indexed_const_iterator (const container_type &c, size_type it): container_const_reference<container_type> (c), it_ (it) {} BOOST_UBLAS_INLINE indexed_const_iterator (const iterator_type &it): container_const_reference<container_type> (it ()), it_ (it.index ()) {} // Arithmetic BOOST_UBLAS_INLINE indexed_const_iterator &operator ++ () { ++ it_; return *this; } BOOST_UBLAS_INLINE indexed_const_iterator &operator -- () { -- it_; return *this; } BOOST_UBLAS_INLINE indexed_const_iterator &operator += (difference_type n) { it_ += n; return *this; } BOOST_UBLAS_INLINE indexed_const_iterator &operator -= (difference_type n) { it_ -= n; return *this; } BOOST_UBLAS_INLINE difference_type operator - (const indexed_const_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_const_iterator &operator = (const indexed_const_iterator &it) { // FIX: ICC needs full qualification?! // assign (&it ()); container_const_reference<C>::assign (&it ()); it_ = it.it_; return *this;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -