vector_of_vector.hpp

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

HPP
1,259
字号
#endif            // Indices            BOOST_UBLAS_INLINE            size_type index1 () const {                BOOST_UBLAS_CHECK (*this != (*this) ().find2 (0, i_, (*this) ().size2 ()), bad_index ());                if (rank_ == 1) {                    BOOST_UBLAS_CHECK (layout_type::index_M (itv_.index (), it_.index ()) < (*this) ().size1 (), bad_index ());                    return layout_type::index_M (itv_.index (), it_.index ());                } else {                    return i_;                }            }            BOOST_UBLAS_INLINE            size_type index2 () const {                BOOST_UBLAS_CHECK (*this != (*this) ().find2 (0, i_, (*this) ().size2 ()), bad_index ());                if (rank_ == 1) {                    BOOST_UBLAS_CHECK (layout_type::index_m (itv_.index (), it_.index ()) < (*this) ().size2 (), bad_index ());                    return layout_type::index_m (itv_.index (), it_.index ());                } else {                    return j_;                }            }            // Assignment             BOOST_UBLAS_INLINE            const_iterator2 &operator = (const const_iterator2 &it) {                container_const_reference<self_type>::assign (&it ());                rank_ = it.rank_;                i_ = it.i_;                j_ = it.j_;                itv_ = it.itv_;                it_ = it.it_;                return *this;            }            // Comparison            BOOST_UBLAS_INLINE            bool operator == (const const_iterator2 &it) const {                BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());                // BOOST_UBLAS_CHECK (rank_ == it.rank_, internal_logic ());                if (rank_ == 1 || it.rank_ == 1) {                    return it_ == it.it_;                } else {                    return i_ == it.i_ && j_ == it.j_;                }            }        private:            int rank_;            size_type i_;            size_type j_;            const_vectoriterator_type itv_;            const_subiterator_type it_;        };        BOOST_UBLAS_INLINE        const_iterator2 begin2 () const {            return find2 (0, 0, 0);        }        BOOST_UBLAS_INLINE        const_iterator2 end2 () const {            return find2 (0, 0, size2_);        }        class iterator2:            public container_reference<generalized_vector_of_vector>,            public bidirectional_iterator_base<sparse_bidirectional_iterator_tag,                                               iterator2, value_type> {        public:            typedef typename generalized_vector_of_vector::difference_type difference_type;            typedef typename generalized_vector_of_vector::value_type value_type;            typedef typename generalized_vector_of_vector::true_reference reference;            typedef typename generalized_vector_of_vector::pointer pointer;            typedef iterator1 dual_iterator_type;            typedef reverse_iterator1 dual_reverse_iterator_type;            // Construction and destruction            BOOST_UBLAS_INLINE            iterator2 ():                container_reference<self_type> (), rank_ (), i_ (), j_ (), itv_ (), it_ () {}            BOOST_UBLAS_INLINE            iterator2 (self_type &m, int rank, size_type i, size_type j, const vectoriterator_type &itv, const subiterator_type &it):                container_reference<self_type> (m), rank_ (rank), i_ (i), j_ (j), itv_ (itv), it_ (it) {}            // Arithmetic            BOOST_UBLAS_INLINE            iterator2 &operator ++ () {                if (rank_ == 1 && layout_type::fast_j ())                    ++ it_;                else {                    self_type &m = (*this) ();                    j_ = index2 () + 1;                    if (rank_ == 1 && ++ itv_ == m.end2 ().itv_)                        *this = m.find2 (rank_, i_, j_, 1);                    else if (rank_ == 1) {                        it_ = (*itv_).begin ();                        if (it_ == (*itv_).end () || index1 () != i_)                            *this = m.find2 (rank_, i_, j_, 1);                    }                }                return *this;            }            BOOST_UBLAS_INLINE            iterator2 &operator -- () {                if (rank_ == 1 && layout_type::fast_j ())                    -- it_;                else {                    self_type &m = (*this) ();                    j_ = index2 () - 1;                    if (rank_ == 1 && -- itv_ == m.end2 ().itv_)                        *this = m.find2 (rank_, i_, j_, -1);                    else if (rank_ == 1) {                        it_ = (*itv_).begin ();                        if (it_ == (*itv_).end () || index1 () != i_)                            *this = m.find2 (rank_, i_, j_, -1);                    }                 }                return *this;            }            // Dereference            BOOST_UBLAS_INLINE            true_reference operator * () const {                BOOST_UBLAS_CHECK (index1 () < (*this) ().size1 (), bad_index ());                BOOST_UBLAS_CHECK (index2 () < (*this) ().size2 (), bad_index ());                if (rank_ == 1) {                    return *it_;                } else {                    return (*this) ().at_element (i_, j_);                }            }#ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION            BOOST_UBLAS_INLINE#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION            typename self_type::#endif            iterator1 begin () const {                self_type &m = (*this) ();                return m.find1 (1, 0, index2 ());            }            BOOST_UBLAS_INLINE#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION            typename self_type::#endif            iterator1 end () const {                self_type &m = (*this) ();                return m.find1 (1, m.size1 (), index2 ());            }            BOOST_UBLAS_INLINE#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION            typename self_type::#endif            reverse_iterator1 rbegin () const {                return reverse_iterator1 (end ());            }            BOOST_UBLAS_INLINE#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION            typename self_type::#endif            reverse_iterator1 rend () const {                return reverse_iterator1 (begin ());            }#endif            // Indices            BOOST_UBLAS_INLINE            size_type index1 () const {                BOOST_UBLAS_CHECK (*this != (*this) ().find2 (0, i_, (*this) ().size2 ()), bad_index ());                if (rank_ == 1) {                    BOOST_UBLAS_CHECK (layout_type::index_M (itv_.index (), it_.index ()) < (*this) ().size1 (), bad_index ());                    return layout_type::index_M (itv_.index (), it_.index ());                } else {                    return i_;                }            }            BOOST_UBLAS_INLINE            size_type index2 () const {                BOOST_UBLAS_CHECK (*this != (*this) ().find2 (0, i_, (*this) ().size2 ()), bad_index ());                if (rank_ == 1) {                    BOOST_UBLAS_CHECK (layout_type::index_m (itv_.index (), it_.index ()) < (*this) ().size2 (), bad_index ());                    return layout_type::index_m (itv_.index (), it_.index ());                } else {                    return j_;                }            }            // Assignment             BOOST_UBLAS_INLINE            iterator2 &operator = (const iterator2 &it) {                container_reference<self_type>::assign (&it ());                rank_ = it.rank_;                i_ = it.i_;                j_ = it.j_;                itv_ = it.itv_;                it_ = it.it_;                return *this;            }            // Comparison            BOOST_UBLAS_INLINE            bool operator == (const iterator2 &it) const {                BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());                // BOOST_UBLAS_CHECK (rank_ == it.rank_, internal_logic ());                if (rank_ == 1 || it.rank_ == 1) {                    return it_ == it.it_;                } else {                    return i_ == it.i_ && j_ == it.j_;                }            }        private:            int rank_;            size_type i_;            size_type j_;            vectoriterator_type itv_;            subiterator_type it_;            friend class const_iterator2;        };        BOOST_UBLAS_INLINE        iterator2 begin2 () {            return find2 (0, 0, 0);        }        BOOST_UBLAS_INLINE        iterator2 end2 () {            return find2 (0, 0, size2_);        }        // Reverse iterators        BOOST_UBLAS_INLINE        const_reverse_iterator1 rbegin1 () const {            return const_reverse_iterator1 (end1 ());        }        BOOST_UBLAS_INLINE        const_reverse_iterator1 rend1 () const {            return const_reverse_iterator1 (begin1 ());        }        BOOST_UBLAS_INLINE        reverse_iterator1 rbegin1 () {            return reverse_iterator1 (end1 ());        }        BOOST_UBLAS_INLINE        reverse_iterator1 rend1 () {            return reverse_iterator1 (begin1 ());        }        BOOST_UBLAS_INLINE        const_reverse_iterator2 rbegin2 () const {            return const_reverse_iterator2 (end2 ());        }        BOOST_UBLAS_INLINE        const_reverse_iterator2 rend2 () const {            return const_reverse_iterator2 (begin2 ());        }        BOOST_UBLAS_INLINE        reverse_iterator2 rbegin2 () {            return reverse_iterator2 (end2 ());        }        BOOST_UBLAS_INLINE        reverse_iterator2 rend2 () {            return reverse_iterator2 (begin2 ());        }         // Serialization        template<class Archive>        void serialize(Archive & ar, const unsigned int /* file_version */){                    // we need to copy to a collection_size_type to get a portable            // and efficient serialization            serialization::collection_size_type s1 (size1_);            serialization::collection_size_type s2 (size2_);                      // serialize the sizes            ar & serialization::make_nvp("size1",s1)               & serialization::make_nvp("size2",s2);            // copy the values back if loading            if (Archive::is_loading::value) {                size1_ = s1;                size2_ = s2;            }            ar & serialization::make_nvp("data", data_);            storage_invariants();        }    private:        void storage_invariants () const        {            BOOST_UBLAS_CHECK (layout_type::size_M (size1_, size2_) + 1 == data_.size (), internal_logic ());            BOOST_UBLAS_CHECK (data ().begin () != data ().end (), internal_logic ());        }        size_type size1_;        size_type size2_;        array_type data_;        static const value_type zero_;    };    template<class T, class L, class A>    const typename generalized_vector_of_vector<T, L, A>::value_type generalized_vector_of_vector<T, L, A>::zero_ = value_type/*zero*/();}}}#endif

⌨️ 快捷键说明

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