iterator.hpp

来自「Boost provides free peer-reviewed portab」· HPP 代码 · 共 1,437 行 · 第 1/4 页

HPP
1,437
字号
        }        BOOST_UBLAS_INLINE        reference operator [] (difference_type n) const {            return *((*this) + n);        }        // Index        BOOST_UBLAS_INLINE        size_type index1 () const {            return it1_;        }        BOOST_UBLAS_INLINE        size_type index2 () const {            return it2_;        }        BOOST_UBLAS_INLINE        dual_iterator_type begin () const {            return (*this) ().find2 (1, index1 (), 0);         }        BOOST_UBLAS_INLINE        dual_iterator_type end () const {            return (*this) ().find2 (1, index1 (), (*this) ().size2 ());         }        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 ());         }        // Assignment        BOOST_UBLAS_INLINE        indexed_const_iterator1 &operator = (const indexed_const_iterator1 &it) {            // FIX: ICC needs full qualification?!            // assign (&it ());            container_const_reference<C>::assign (&it ());            it1_ = it.it1_;            it2_ = it.it2_;            return *this;        }        // Comparison        BOOST_UBLAS_INLINE        bool operator == (const indexed_const_iterator1 &it) const {            BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());            BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ());            return it1_ == it.it1_;        }        BOOST_UBLAS_INLINE        bool operator < (const indexed_const_iterator1 &it) const {            BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());            BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ());            return it1_ < it.it1_;        }    private:        size_type it1_;        size_type it2_;        friend class indexed_iterator1<container_type, iterator_category>;    };  /** \brief A class implementing an indexed random access iterator    * of a matrix.   *   * \param C the (mutable) container type   * \param IC the iterator category   *   * This class implements a random access iterator. The current   * position is stored as two unsigned integers \c it1_ and \c it2_   * and the values are accessed via \c operator()(it1_, it2_) of the   * container. The iterator changes the second index.   *   * uBLAS extension: \c index1(), \c index2() and access to the   * dual iterator via \c begin(), \c end(), \c rbegin() and \c rend()   *   * Note: The container has to support the find1(rank, i, j) method   */    template<class C, class IC>    class indexed_iterator2:        public container_reference<C>,         public random_access_iterator_base<IC,                                           indexed_iterator2<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;        typedef indexed_iterator1<container_type, iterator_category> dual_iterator_type;        typedef reverse_iterator_base1<dual_iterator_type> dual_reverse_iterator_type;        // Construction and destruction        BOOST_UBLAS_INLINE        indexed_iterator2 ():            container_reference<container_type> (), it1_ (), it2_ () {}        BOOST_UBLAS_INLINE        indexed_iterator2 (container_type &c, size_type it1, size_type it2):            container_reference<container_type> (c), it1_ (it1), it2_ (it2) {}        // Arithmetic        BOOST_UBLAS_INLINE        indexed_iterator2 &operator ++ () {            ++ it2_;            return *this;        }        BOOST_UBLAS_INLINE        indexed_iterator2 &operator -- () {            -- it2_;            return *this;        }        BOOST_UBLAS_INLINE        indexed_iterator2 &operator += (difference_type n) {            it2_ += n;            return *this;        }        BOOST_UBLAS_INLINE        indexed_iterator2 &operator -= (difference_type n) {            it2_ -= n;            return *this;        }        BOOST_UBLAS_INLINE        difference_type operator - (const indexed_iterator2 &it) const {            BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());            BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ());            return it2_ - it.it2_;        }        // Dereference        BOOST_UBLAS_INLINE        reference operator * () const {            BOOST_UBLAS_CHECK (index1 () < (*this) ().size1 (), bad_index ());            BOOST_UBLAS_CHECK (index2 () < (*this) ().size2 (), bad_index ());            return (*this) () (it1_, it2_);        }        BOOST_UBLAS_INLINE        reference operator [] (difference_type n) const {            return *((*this) + n);        }        // Index        BOOST_UBLAS_INLINE        size_type index1 () const {            return it1_;        }        BOOST_UBLAS_INLINE        size_type index2 () const {            return it2_;        }        BOOST_UBLAS_INLINE        dual_iterator_type begin () const {            return (*this) ().find1 (1, 0, index2 ());        }        BOOST_UBLAS_INLINE        dual_iterator_type end () const {            return (*this) ().find1 (1, (*this) ().size1 (), index2 ());        }        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 ());        }        // Assignment        BOOST_UBLAS_INLINE        indexed_iterator2 &operator = (const indexed_iterator2 &it) {            // FIX: ICC needs full qualification?!            // assign (&it ());            container_reference<C>::assign (&it ());            it1_ = it.it1_;            it2_ = it.it2_;            return *this;        }        // Comparison        BOOST_UBLAS_INLINE        bool operator == (const indexed_iterator2 &it) const {            BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());            BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ());            return it2_ == it.it2_;        }        BOOST_UBLAS_INLINE        bool operator < (const indexed_iterator2 &it) const {            BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());            BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ());            return it2_ < it.it2_;        }    private:        size_type it1_;        size_type it2_;    };  /** \brief A class implementing an indexed random access iterator    * of a matrix.   *   * \param C the (immutable) container type   * \param IC the iterator category   *   * This class implements a random access iterator. The current   * position is stored as two unsigned integers \c it1_ and \c it2_   * and the values are accessed via \c operator()(it1_, it2_) of the   * container. The iterator changes the second index.   *   * uBLAS extension: \c index1(), \c index2() and access to the   * dual iterator via \c begin(), \c end(), \c rbegin() and \c rend()   *   * Note 1: The container has to support the \c find2(rank, i, j) method   *   * Note 2: there is an automatic conversion from    * \c indexed_iterator2 to \c indexed_const_iterator2   */    template<class C, class IC>    class indexed_const_iterator2:        public container_const_reference<C>,        public random_access_iterator_base<IC,                                           indexed_const_iterator2<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_iterator2<container_type, iterator_category> iterator_type;        typedef indexed_const_iterator1<container_type, iterator_category> dual_iterator_type;        typedef reverse_iterator_base1<dual_iterator_type> dual_reverse_iterator_type;        // Construction and destruction        BOOST_UBLAS_INLINE        indexed_const_iterator2 ():            container_const_reference<container_type> (), it1_ (), it2_ () {}        BOOST_UBLAS_INLINE        indexed_const_iterator2 (const container_type &c, size_type it1, size_type it2):            container_const_reference<container_type> (c), it1_ (it1), it2_ (it2) {}        BOOST_UBLAS_INLINE        indexed_const_iterator2 (const iterator_type &it):            container_const_reference<container_type> (it ()), it1_ (it.index1 ()), it2_ (it.index2 ()) {}        // Arithmetic        BOOST_UBLAS_INLINE        indexed_const_iterator2 &operator ++ () {            ++ it2_;            return *this;        }        BOOST_UBLAS_INLINE        indexed_const_iterator2 &operator -- () {            -- it2_;            return *this;        }        BOOST_UBLAS_INLINE        indexed_const_iterator2 &operator += (difference_type n) {            it2_ += n;            return *this;        }        BOOST_UBLAS_INLINE        indexed_const_iterator2 &operator -= (difference_type n) {            it2_ -= n;            return *this;        }        BOOST_UBLAS_INLINE        difference_type operator - (const indexed_const_iterator2 &it) const {            BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());            BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ());            return it2_ - it.it2_;        }        // Dereference        BOOST_UBLAS_INLINE        reference operator * () const {            BOOST_UBLAS_CHECK (index1 () < (*this) ().size1 (), bad_index ());            BOOST_UBLAS_CHECK (index2 () < (*this) ().size2 (), bad_index ());            return (*this) () (it1_, it2_);        }        BOOST_UBLAS_INLINE        reference operator [] (difference_type n) const {            return *((*this) + n);        }        // Index        BOOST_UBLAS_INLINE        size_type index1 () const {            return it1_;        }        BOOST_UBLAS_INLINE        size_type index2 () const {            return it2_;        }        BOOST_UBLAS_INLINE        dual_iterator_type begin () const {            return (*this) ().find1 (1, 0, index2 ());        }        BOOST_UBLAS_INLINE        dual_iterator_type end () const {            return (*this) ().find1 (1, (*this) ().size1 (), index2 ());        }        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 ());        }        // Assignment        BOOST_UBLAS_INLINE        indexed_const_iterator2 &operator = (const indexed_const_iterator2 &it) {            // FIX: ICC needs full qualification?!            // assign (&it ());            container_const_reference<C>::assign (&it ());            it1_ = it.it1_;            it2_ = it.it2_;            return *this;        }        // Comparison        BOOST_UBLAS_INLINE        bool operator == (const indexed_const_iterator2 &it) const {            BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());            BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ());            return it2_ == it.it2_;        }        BOOST_UBLAS_INLINE        bool operator < (const indexed_const_iterator2 &it) const {            BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());            BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ());            return it2_ < it.it2_;        }    private:        size_type it1_;        size_type it2_;        friend class indexed_iterator2<container_type, iterator_category>;    };}}}#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?