vector_proxy.hpp
来自「Boost provides free peer-reviewed portab」· HPP 代码 · 共 1,567 行 · 第 1/4 页
HPP
1,567 行
const_iterator &operator ++ () { ++ it_; return *this; } BOOST_UBLAS_INLINE const_iterator &operator -- () { -- it_; return *this; } BOOST_UBLAS_INLINE const_iterator &operator += (difference_type n) { it_ += n; return *this; } BOOST_UBLAS_INLINE const_iterator &operator -= (difference_type n) { it_ -= n; return *this; } BOOST_UBLAS_INLINE difference_type operator - (const const_iterator &it) const { BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ()); return it_ - it.it_; } // Dereference BOOST_UBLAS_INLINE const_reference operator * () const { // FIXME replace find with at_element BOOST_UBLAS_CHECK (index () < (*this) ().size (), bad_index ()); return (*this) ().data_ (*it_); } BOOST_UBLAS_INLINE const_reference operator [] (difference_type n) const { return *(*this + n); } // Index BOOST_UBLAS_INLINE size_type index () const { return it_.index (); } // Assignment BOOST_UBLAS_INLINE const_iterator &operator = (const const_iterator &it) { container_const_reference<self_type>::assign (&it ()); it_ = it.it_; return *this; } // Comparison BOOST_UBLAS_INLINE bool operator == (const const_iterator &it) const { BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ()); return it_ == it.it_; } BOOST_UBLAS_INLINE bool operator < (const const_iterator &it) const { BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ()); return it_ < it.it_; } private: const_subiterator_type it_; };#endif BOOST_UBLAS_INLINE const_iterator begin () const { return find (0); } BOOST_UBLAS_INLINE const_iterator end () const { return find (size ()); }#ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR class iterator: public container_reference<vector_slice>, public iterator_base_traits<typename V::iterator::iterator_category>::template iterator_base<iterator, value_type>::type { public: typedef typename V::iterator::difference_type difference_type; typedef typename V::iterator::value_type value_type; typedef typename V::reference reference; //FIXME due to indexing access typedef typename V::iterator::pointer pointer; // Construction and destruction BOOST_UBLAS_INLINE iterator (): container_reference<self_type> (), it_ () {} BOOST_UBLAS_INLINE iterator (self_type &vs, const subiterator_type &it): container_reference<self_type> (vs), it_ (it) {} // Arithmetic BOOST_UBLAS_INLINE iterator &operator ++ () { ++ it_; return *this; } BOOST_UBLAS_INLINE iterator &operator -- () { -- it_; return *this; } BOOST_UBLAS_INLINE iterator &operator += (difference_type n) { it_ += n; return *this; } BOOST_UBLAS_INLINE iterator &operator -= (difference_type n) { it_ -= n; return *this; } BOOST_UBLAS_INLINE difference_type operator - (const iterator &it) const { BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ()); return it_ - it.it_; } // Dereference BOOST_UBLAS_INLINE reference operator * () const { // FIXME replace find with at_element BOOST_UBLAS_CHECK (index () < (*this) ().size (), bad_index ()); return (*this) ().data_ (*it_); } BOOST_UBLAS_INLINE reference operator [] (difference_type n) const { return *(*this + n); } // Index BOOST_UBLAS_INLINE size_type index () const { return it_.index (); } // Assignment BOOST_UBLAS_INLINE iterator &operator = (const iterator &it) { container_reference<self_type>::assign (&it ()); it_ = it.it_; return *this; } // Comparison BOOST_UBLAS_INLINE bool operator == (const iterator &it) const { BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ()); return it_ == it.it_; } BOOST_UBLAS_INLINE bool operator < (const iterator &it) const { BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ()); return it_ < it.it_; } private: subiterator_type it_; friend class const_iterator; };#endif BOOST_UBLAS_INLINE iterator begin () { return find (0); } BOOST_UBLAS_INLINE iterator end () { return find (size ()); } // Reverse iterator typedef reverse_iterator_base<const_iterator> const_reverse_iterator; typedef reverse_iterator_base<iterator> reverse_iterator; BOOST_UBLAS_INLINE const_reverse_iterator rbegin () const { return const_reverse_iterator (end ()); } BOOST_UBLAS_INLINE const_reverse_iterator rend () const { return const_reverse_iterator (begin ()); } BOOST_UBLAS_INLINE reverse_iterator rbegin () { return reverse_iterator (end ()); } BOOST_UBLAS_INLINE reverse_iterator rend () { return reverse_iterator (begin ()); } private: vector_closure_type data_; slice_type s_; }; // Simple Projections template<class V> BOOST_UBLAS_INLINE vector_slice<V> subslice (V &data, typename V::size_type start, typename V::difference_type stride, typename V::size_type size) { typedef basic_slice<typename V::size_type, typename V::difference_type> slice_type; return vector_slice<V> (data, slice_type (start, stride, size)); } template<class V> BOOST_UBLAS_INLINE vector_slice<const V> subslice (const V &data, typename V::size_type start, typename V::difference_type stride, typename V::size_type size) { typedef basic_slice<typename V::size_type, typename V::difference_type> slice_type; return vector_slice<const V> (data, slice_type (start, stride, size)); } // Generic Projections template<class V> BOOST_UBLAS_INLINE vector_slice<V> project (V &data, const typename vector_slice<V>::slice_type &s) { return vector_slice<V> (data, s); } template<class V> BOOST_UBLAS_INLINE const vector_slice<const V> project (const V &data, const typename vector_slice<V>::slice_type &s) { // ISSUE was: return vector_slice<V> (const_cast<V &> (data), s); return vector_slice<const V> (data, s); } template<class V> BOOST_UBLAS_INLINE vector_slice<V> project (vector_slice<V> &data, const typename vector_slice<V>::slice_type &s) { return data.project (s); } template<class V> BOOST_UBLAS_INLINE const vector_slice<V> project (const vector_slice<V> &data, const typename vector_slice<V>::slice_type &s) { return data.project (s); } // ISSUE in the following two functions it would be logical to use vector_slice<V>::range_type but this confuses VC7.1 and 8.0 template<class V> BOOST_UBLAS_INLINE vector_slice<V> project (vector_slice<V> &data, const typename vector_range<V>::range_type &r) { return data.project (r); } template<class V> BOOST_UBLAS_INLINE const vector_slice<V> project (const vector_slice<V> &data, const typename vector_range<V>::range_type &r) { return data.project (r); } // Specialization of temporary_traits template <class V> struct vector_temporary_traits< vector_slice<V> > : vector_temporary_traits< V > {} ; template <class V> struct vector_temporary_traits< const vector_slice<V> > : vector_temporary_traits< V > {} ; // Vector based indirection class // Contributed by Toon Knapen. // Extended and optimized by Kresimir Fresl. template<class V, class IA> class vector_indirect: public vector_expression<vector_indirect<V, IA> > { typedef vector_indirect<V, IA> self_type; public:#ifdef BOOST_UBLAS_ENABLE_PROXY_SHORTCUTS using vector_expression<self_type>::operator ();#endif typedef const V const_vector_type; typedef V vector_type; typedef const IA const_indirect_array_type; typedef IA indirect_array_type; typedef typename V::size_type size_type; typedef typename V::difference_type difference_type; typedef typename V::value_type value_type; typedef typename V::const_reference const_reference; typedef typename boost::mpl::if_<boost::is_const<V>, typename V::const_reference, typename V::reference>::type reference; typedef typename boost::mpl::if_<boost::is_const<V>, typename V::const_closure_type, typename V::closure_type>::type vector_closure_type; typedef basic_range<size_type, difference_type> range_type; typedef basic_slice<size_type, difference_type> slice_type; typedef const self_type const_closure_type; typedef self_type closure_type; typedef typename storage_restrict_traits<typename V::storage_category, dense_proxy_tag>::storage_category storage_category; // Construction and destruction BOOST_UBLAS_INLINE vector_indirect (vector_type &data, size_type size): data_ (data), ia_ (size) {} BOOST_UBLAS_INLINE vector_indirect (vector_type &data, const indirect_array_type &ia): data_ (data), ia_ (ia.preprocess (data.size ())) {} BOOST_UBLAS_INLINE vector_indirect (const vector_closure_type &data, const indirect_array_type &ia, int): data_ (data), ia_ (ia.preprocess (data.size ())) {} // Accessors BOOST_UBLAS_INLINE size_type size () const { return ia_.size (); } BOOST_UBLAS_INLINE const_indirect_array_type &indirect () const { return ia_; } BOOST_UBLAS_INLINE indirect_array_type &indirect () { return ia_; } // Storage accessors BOOST_UBLAS_INLINE const vector_closure_type &data () const { return data_; } BOOST_UBLAS_INLINE vector_closure_type &data () { return data_; } // Element access#ifndef BOOST_UBLAS_PROXY_CONST_MEMBER BOOST_UBLAS_INLINE const_reference operator () (size_type i) const { return data_ (ia_ (i)); } BOOST_UBLAS_INLINE reference operator () (size_type i) { return data_ (ia_ (i)); } BOOST_UBLAS_INLINE const_reference operator [] (size_type i) const { return (*this) (i); } BOOST_UBLAS_INLINE reference operator [] (size_type i) { return (*this) (i); }#else BOOST_UBLAS_INLINE reference operator () (size_type i) const { return data_ (ia_ (i)); } BOOST_UBLAS_INLINE reference operator [] (size_type i) const { return (*this) (i); }#endif // ISSUE can this be done in free project function? // Although a const function can create a non-const proxy to a non-const object // Critical is that vector_type and data_ (vector_closure_type) are const correct BOOST_UBLAS_INLINE vector_indirect<vector_type, indirect_array_type> project (const range_type &r) const { return vector_indirect<vector_type, indirect_array_type> (data_, ia_.compose (r.preprocess (data_.size ())), 0); } BOOST_UBLAS_INLINE vector_indirect<vector_type, indirect_array_type> project (const slice_type &s) const { return vector_indirect<vector_type, indirect_array_type> (data_, ia_.compose (s.preprocess (data_.size ())), 0); } BOOST_UBLAS_INLINE vector_indirect<vector_type, indirect_array_type> project (const indirect_array_type &ia) const { return vector_indirect<vector_type, indirect_array_type> (data_, ia_.compose (ia.preprocess (data_.size ())), 0); } // Assignment BOOST_UBLAS_INLINE vector_indirect &operator = (const vector_indirect &vi) { // ISSUE need a temporary, proxy can be overlaping alias vector_assign<scalar_assign> (*this, typename vector_temporary_traits<V>::type (vi)); return *this; } BOOST_UBLAS_INLINE vector_indirect &assign_temporary (vector_indirect &vi) { // assign elements, proxied container remains the same vector_assign<scalar_assign> (*this, vi); return *this; } template<class AE> BOOST_UBLAS_INLINE vector_indirect &operator = (const vector_expression<AE> &ae) {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?