📄 vector_expression.hpp
字号:
BOOST_UBLAS_INLINE reference operator [] (size_type i) { return expression () [i]; }#else BOOST_UBLAS_INLINE reference operator () (size_type i) const { return expression () (i); } BOOST_UBLAS_INLINE reference operator [] (size_type i) const { return expression () [i]; }#endif // Assignment BOOST_UBLAS_INLINE vector_reference &operator = (const vector_reference &v) { expression ().operator = (v); return *this; } template<class AE> BOOST_UBLAS_INLINE vector_reference &operator = (const vector_expression<AE> &ae) { expression ().operator = (ae); return *this; } template<class AE> BOOST_UBLAS_INLINE vector_reference &assign (const vector_expression<AE> &ae) { expression ().assign (ae); return *this; } template<class AE> BOOST_UBLAS_INLINE vector_reference &operator += (const vector_expression<AE> &ae) { expression ().operator += (ae); return *this; } template<class AE> BOOST_UBLAS_INLINE vector_reference &plus_assign (const vector_expression<AE> &ae) { expression ().plus_assign (ae); return *this; } template<class AE> BOOST_UBLAS_INLINE vector_reference &operator -= (const vector_expression<AE> &ae) { expression ().operator -= (ae); return *this; } template<class AE> BOOST_UBLAS_INLINE vector_reference &minus_assign (const vector_expression<AE> &ae) { expression ().minus_assign (ae); return *this; } template<class AT> BOOST_UBLAS_INLINE vector_reference &operator *= (const AT &at) { expression ().operator *= (at); return *this; } template<class AT> BOOST_UBLAS_INLINE vector_reference &operator /= (const AT &at) { expression ().operator /= (at); return *this; } // Swapping BOOST_UBLAS_INLINE void swap (vector_reference &v) { expression ().swap (v.expression ()); } // Closure comparison BOOST_UBLAS_INLINE bool same_closure (const vector_reference &vr) const { return &(*this).e_ == &vr.e_; } // Iterator types#ifndef BOOST_UBLAS_CT_REFERENCE_BASE_TYPEDEFS typedef typename T::const_iterator const_iterator; typedef typename T::iterator iterator;#else typedef typename T::const_iterator const_iterator; typedef typename boost::mpl::if_<boost::is_const<T>, typename T::const_iterator, typename T::iterator>::type iterator;#endif // Element lookup BOOST_UBLAS_INLINE const_iterator find (size_type i) const { return expression ().find (i); } BOOST_UBLAS_INLINE iterator find (size_type i) { return expression ().find (i); } // Iterator is the iterator of the referenced expression. BOOST_UBLAS_INLINE const_iterator begin () const { return expression ().begin (); } BOOST_UBLAS_INLINE const_iterator end () const { return expression ().end (); } BOOST_UBLAS_INLINE iterator begin () { return expression ().begin (); } BOOST_UBLAS_INLINE iterator end () { return expression ().end (); } // Reverse iterator#ifdef BOOST_MSVC_STD_ITERATOR typedef reverse_iterator_base<const_iterator, value_type, const_reference> const_reverse_iterator;#else typedef reverse_iterator_base<const_iterator> const_reverse_iterator;#endif 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 ()); }#ifdef BOOST_MSVC_STD_ITERATOR typedef reverse_iterator_base<iterator, value_type, reference> reverse_iterator;#else typedef reverse_iterator_base<iterator> reverse_iterator;#endif BOOST_UBLAS_INLINE reverse_iterator rbegin () { return reverse_iterator (end ()); } BOOST_UBLAS_INLINE reverse_iterator rend () { return reverse_iterator (begin ()); } private: refered_type &e_; static refered_type nil_; }; template<class T> typename vector_reference<T>::refered_type vector_reference<T>::nil_#ifdef BOOST_UBLAS_STATIC_OLD_INIT = BOOST_UBLAS_TYPENAME vector_reference<T>::refered_type ()#endif ; template<class E, class F> class vector_unary: public vector_expression<vector_unary<E, F> > { public:#ifndef BOOST_UBLAS_NO_PROXY_SHORTCUTS BOOST_UBLAS_USING vector_expression<vector_unary<E, F> >::operator ();#endif typedef typename boost::mpl::if_<boost::is_same<F, scalar_identity<typename E::value_type> >, E, const E>::type expression_type; typedef typename E::size_type size_type; typedef typename E::difference_type difference_type; typedef typename F::result_type value_type; typedef value_type const_reference; typedef typename boost::mpl::if_<boost::is_same<F, scalar_identity<value_type> >, typename E::reference, value_type>::type reference; private: typedef const value_type *const_pointer; typedef F functor_type; typedef typename boost::mpl::if_<boost::is_const<expression_type>, typename E::const_closure_type, typename E::closure_type>::type expression_closure_type; typedef vector_unary<E, F> self_type; public: typedef const self_type const_closure_type; typedef self_type closure_type; typedef unknown_storage_tag storage_category; // Construction and destruction BOOST_UBLAS_INLINE vector_unary (): e_ () {} BOOST_UBLAS_INLINE // ISSUE may be used as mutable expression. // vector_unary (const expression_type &e): explicit vector_unary (expression_type &e): e_ (e) {} // Accessors BOOST_UBLAS_INLINE size_type size () const { return e_.size (); }#ifndef BOOST_UBLAS_NESTED_CLASS_DR45 private:#endif // Expression accessors BOOST_UBLAS_INLINE const expression_closure_type &expression () const { return e_; } public: // Element access BOOST_UBLAS_INLINE const_reference operator () (size_type i) const { return functor_type::apply (e_ (i)); } BOOST_UBLAS_INLINE reference operator () (size_type i) { BOOST_STATIC_ASSERT ((boost::is_same<functor_type, scalar_identity<value_type > >::value)); return e_ (i); } BOOST_UBLAS_INLINE const_reference operator [] (size_type i) const { return functor_type::apply (e_ [i]); } BOOST_UBLAS_INLINE reference operator [] (size_type i) { BOOST_STATIC_ASSERT ((boost::is_same<functor_type, scalar_identity<value_type > >::value)); return e_ [i]; } // Closure comparison BOOST_UBLAS_INLINE bool same_closure (const vector_unary &vu) const { return (*this).expression ().same_closure (vu.expression ()); } // Iterator types private: typedef typename E::const_iterator const_iterator_type; public:#ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR typedef indexed_const_iterator<const_closure_type, typename const_iterator_type::iterator_category> const_iterator; typedef const_iterator iterator;#else class const_iterator; typedef const_iterator iterator;#endif // Element lookup BOOST_UBLAS_INLINE const_iterator find (size_type i) const {#ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR const_iterator_type it (e_.find (i)); return const_iterator (*this, it.index ());#else return const_iterator (*this, e_.find (i));#endif } // Iterator enhances the iterator of the referenced expression // with the unary functor.#ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR class const_iterator: public container_const_reference<vector_unary>,#ifndef BOOST_UBLAS_NO_ITERATOR_BASE_TRAITS public iterator_base_traits<typename E::const_iterator::iterator_category>::template iterator_base<const_iterator, value_type>::type {#else public random_access_iterator_base<typename E::const_iterator::iterator_category, const_iterator, value_type> {#endif public: typedef typename E::const_iterator::iterator_category iterator_category;#ifdef BOOST_MSVC_STD_ITERATOR typedef const_reference reference;#else typedef typename vector_unary::difference_type difference_type; typedef typename vector_unary::value_type value_type; typedef typename vector_unary::const_reference reference; typedef typename vector_unary::const_pointer pointer;#endif // Construction and destruction BOOST_UBLAS_INLINE const_iterator (): container_const_reference<self_type> (), it_ () {} BOOST_UBLAS_INLINE const_iterator (const self_type &vu, const const_iterator_type &it): container_const_reference<self_type> (vu), it_ (it) {} // Arithmetic BOOST_UBLAS_INLINE 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 { return functor_type::apply (*it_); } // 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_;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -