iterator.hpp

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

HPP
1,437
字号
        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_;    };  /** \brief A class implementing an indexed random access iterator.   *   * \param C the (immutable) 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;        }        // Comparison        BOOST_UBLAS_INLINE        bool operator == (const indexed_const_iterator &it) const {            BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());            return it_ == it.it_;        }        BOOST_UBLAS_INLINE        bool operator < (const indexed_const_iterator &it) const {            BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());            return it_ < it.it_;        }    private:        size_type it_;        friend class indexed_iterator<container_type, iterator_category>;    };    template<class C, class IC>    class indexed_iterator2;  /** \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 first 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 \code find2(rank, i, j) \endcode    * method   */    template<class C, class IC>    class indexed_iterator1:        public container_reference<C>,         public random_access_iterator_base<IC,                                           indexed_iterator1<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_iterator2<container_type, iterator_category> dual_iterator_type;        typedef reverse_iterator_base2<dual_iterator_type> dual_reverse_iterator_type;        // Construction and destruction        BOOST_UBLAS_INLINE        indexed_iterator1 ():            container_reference<container_type> (), it1_ (), it2_ () {}        BOOST_UBLAS_INLINE         indexed_iterator1 (container_type &c, size_type it1, size_type it2):            container_reference<container_type> (c), it1_ (it1), it2_ (it2) {}        // Arithmetic        BOOST_UBLAS_INLINE        indexed_iterator1 &operator ++ () {            ++ it1_;            return *this;        }        BOOST_UBLAS_INLINE        indexed_iterator1 &operator -- () {            -- it1_;            return *this;        }        BOOST_UBLAS_INLINE        indexed_iterator1 &operator += (difference_type n) {            it1_ += n;            return *this;        }        BOOST_UBLAS_INLINE        indexed_iterator1 &operator -= (difference_type n) {            it1_ -= n;            return *this;        }        BOOST_UBLAS_INLINE        difference_type operator - (const indexed_iterator1 &it) const {            BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());            BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ());            return it1_ - it.it1_;        }        // 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) ().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_iterator1 &operator = (const indexed_iterator1 &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_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_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_;    };    template<class C, class IC>    class indexed_const_iterator2;  /** \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 first 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 find2(rank, i, j) method   *   * Note 2: there is an automatic conversion from    * \c indexed_iterator1 to \c indexed_const_iterator1   */    template<class C, class IC>    class indexed_const_iterator1:        public container_const_reference<C>,         public random_access_iterator_base<IC,                                           indexed_const_iterator1<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_iterator1<container_type, iterator_category> iterator_type;        typedef indexed_const_iterator2<container_type, iterator_category> dual_iterator_type;        typedef reverse_iterator_base2<dual_iterator_type> dual_reverse_iterator_type;        // Construction and destruction        BOOST_UBLAS_INLINE        indexed_const_iterator1 ():            container_const_reference<container_type> (), it1_ (), it2_ () {}        BOOST_UBLAS_INLINE        indexed_const_iterator1 (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_iterator1 (const iterator_type &it):            container_const_reference<container_type> (it ()), it1_ (it.index1 ()), it2_ (it.index2 ()) {}        // Arithmetic        BOOST_UBLAS_INLINE        indexed_const_iterator1 &operator ++ () {            ++ it1_;            return *this;        }        BOOST_UBLAS_INLINE        indexed_const_iterator1 &operator -- () {            -- it1_;            return *this;        }        BOOST_UBLAS_INLINE        indexed_const_iterator1 &operator += (difference_type n) {            it1_ += n;            return *this;        }        BOOST_UBLAS_INLINE        indexed_const_iterator1 &operator -= (difference_type n) {            it1_ -= n;            return *this;        }        BOOST_UBLAS_INLINE        difference_type 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_;        }        // 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_);

⌨️ 快捷键说明

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