📄 vector_expression.hpp
字号:
if (it2_.index () == i_) t2 = *it2_; return functor_type::apply (t1, t2); } // Arithmetic BOOST_UBLAS_INLINE const_iterator &operator ++ () { increment (iterator_category ()); return *this; } BOOST_UBLAS_INLINE const_iterator &operator -- () { decrement (iterator_category ()); return *this; } BOOST_UBLAS_INLINE const_iterator &operator += (difference_type n) { i_ += n, it1_ += n, it2_ += n; return *this; } BOOST_UBLAS_INLINE const_iterator &operator -= (difference_type n) { i_ -= n, it1_ -= n, it2_ -= n; return *this; } BOOST_UBLAS_INLINE difference_type operator - (const const_iterator &it) const { BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ()); return index () - it.index (); } // Dereference BOOST_UBLAS_INLINE const_reference operator * () const { return dereference (iterator_category ()); } // Index BOOST_UBLAS_INLINE size_type index () const { return i_; } // Assignment BOOST_UBLAS_INLINE const_iterator &operator = (const const_iterator &it) { container_const_reference<self_type>::assign (&it ()); i_ = it.i_; it1_ = it.it1_; it1_end_ = it.it1_end_; it2_ = it.it2_; it2_end_ = it.it2_end_; return *this; } // Comparison BOOST_UBLAS_INLINE bool operator == (const const_iterator &it) const { BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ()); return index () == it.index (); } BOOST_UBLAS_INLINE bool operator < (const const_iterator &it) const { BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ()); return index () < it.index (); } private: size_type i_; const_iterator1_type it1_; const_iterator1_type it1_end_; const_iterator2_type it2_; const_iterator2_type it2_end_; };#endif BOOST_UBLAS_INLINE const_iterator begin () const { return find (0); } BOOST_UBLAS_INLINE const_iterator end () const { return find (size ()); } // 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 ()); } private: expression1_closure_type e1_; expression2_closure_type e2_; }; template<class E1, class E2, class F> struct vector_binary_traits { typedef vector_binary<E1, E2, F> expression_type;#ifndef BOOST_UBLAS_SIMPLE_ET_DEBUG typedef expression_type result_type; #else typedef typename E1::vector_temporary_type result_type;#endif }; // (v1 + v2) [i] = v1 [i] + v2 [i] template<class E1, class E2> BOOST_UBLAS_INLINE typename vector_binary_traits<E1, E2, scalar_plus<typename E1::value_type, typename E2::value_type> >::result_type operator + (const vector_expression<E1> &e1, const vector_expression<E2> &e2) { typedef BOOST_UBLAS_TYPENAME vector_binary_traits<E1, E2, scalar_plus<BOOST_UBLAS_TYPENAME E1::value_type, BOOST_UBLAS_TYPENAME E2::value_type> >::expression_type expression_type; return expression_type (e1 (), e2 ()); } // (v1 - v2) [i] = v1 [i] - v2 [i] template<class E1, class E2> BOOST_UBLAS_INLINE typename vector_binary_traits<E1, E2, scalar_minus<typename E1::value_type, typename E2::value_type> >::result_type operator - (const vector_expression<E1> &e1, const vector_expression<E2> &e2) { typedef BOOST_UBLAS_TYPENAME vector_binary_traits<E1, E2, scalar_minus<BOOST_UBLAS_TYPENAME E1::value_type, BOOST_UBLAS_TYPENAME E2::value_type> >::expression_type expression_type; return expression_type (e1 (), e2 ()); } // (v1 * v2) [i] = v1 [i] * v2 [i] template<class E1, class E2> BOOST_UBLAS_INLINE typename vector_binary_traits<E1, E2, scalar_multiplies<typename E1::value_type, typename E2::value_type> >::result_type element_prod (const vector_expression<E1> &e1, const vector_expression<E2> &e2) { typedef BOOST_UBLAS_TYPENAME vector_binary_traits<E1, E2, scalar_multiplies<BOOST_UBLAS_TYPENAME E1::value_type, BOOST_UBLAS_TYPENAME E2::value_type> >::expression_type expression_type; return expression_type (e1 (), e2 ()); } // (v1 / v2) [i] = v1 [i] / v2 [i] template<class E1, class E2> BOOST_UBLAS_INLINE typename vector_binary_traits<E1, E2, scalar_divides<typename E1::value_type, typename E2::value_type> >::result_type element_div (const vector_expression<E1> &e1, const vector_expression<E2> &e2) { typedef BOOST_UBLAS_TYPENAME vector_binary_traits<E1, E2, scalar_divides<BOOST_UBLAS_TYPENAME E1::value_type, BOOST_UBLAS_TYPENAME E2::value_type> >::expression_type expression_type; return expression_type (e1 (), e2 ()); } template<class E1, class E2, class F, class C1> class vector_binary_scalar1: public vector_expression<vector_binary_scalar1<E1, E2, F, C1> > { public:#ifndef BOOST_UBLAS_NO_PROXY_SHORTCUTS BOOST_UBLAS_USING vector_expression<vector_binary_scalar1<E1, E2, F, C1> >::operator ();#endif typedef typename E2::size_type size_type; typedef typename E2::difference_type difference_type; typedef typename F::result_type value_type; typedef value_type const_reference; typedef const_reference reference; private: typedef const value_type *const_pointer; typedef F functor_type; typedef E1 expression1_type; typedef E2 expression2_type; typedef C1 expression1_closure_type; typedef typename E2::const_closure_type expression2_closure_type; typedef vector_binary_scalar1<E1, E2, F, C1> self_type; public: typedef const self_type const_closure_type; typedef const_closure_type closure_type; typedef unknown_storage_tag storage_category; // Construction and destruction BOOST_UBLAS_INLINE vector_binary_scalar1 (): e1_ (), e2_ () {} BOOST_UBLAS_INLINE vector_binary_scalar1 (const expression1_type &e1, const expression2_type &e2): e1_ (e1), e2_ (e2) {} // Accessors BOOST_UBLAS_INLINE size_type size () const { return e2_.size (); } public: // Element access BOOST_UBLAS_INLINE const_reference operator () (size_type i) const { return functor_type::apply (expression1_type (e1_), e2_ (i)); } BOOST_UBLAS_INLINE const_reference operator [] (size_type i) const { return functor_type::apply (expression1_type (e1_), e2_ [i]); } // Closure comparison BOOST_UBLAS_INLINE bool same_closure (const vector_binary_scalar1 &vbs1) const { return (*this).e1_.same_closure (vbs1.e1_) && (*this).e2_.same_closure (vbs1.e2_); } // Iterator types private: typedef expression1_type const_iterator1_type; typedef typename expression2_type::const_iterator const_iterator2_type; public:#ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR typedef indexed_const_iterator<const_closure_type, typename const_iterator2_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_iterator2_type it (e2_.find (i)); return const_iterator (*this, it.index ());#else return const_iterator (*this, const_iterator1_type (e1_), e2_.find (i));#endif } // Iterator enhances the iterator of the referenced vector expression // with the binary functor.#ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR class const_iterator: public container_const_reference<vector_binary_scalar1>,#ifndef BOOST_UBLAS_NO_ITERATOR_BASE_TRAITS public iterator_base_traits<typename E2::const_iterator::iterator_category>::template iterator_base<const_iterator, value_type>::type {#else public random_access_iterator_base<typename E2::const_iterator::iterator_category, const_iterator, value_type> {#endif public: typedef typename E2::const_iterator::iterator_category iterator_category;#ifdef BOOST_MSVC_STD_ITERATOR typedef const_reference reference;#else typedef typename vector_binary_scalar1::difference_type difference_type; typedef typename vector_binary_scalar1::value_type value_type; typedef typename vector_binary_scalar1::const_reference reference; typedef typename vector_binary_scalar1::const_pointer pointer;#endif // Construction and destruction BOOST_UBLAS_INLINE const_iterator (): container_const_reference<self_type> (), it1_ (), it2_ () {} BOOST_UBLAS_INLINE const_iterator (const self_type &vbs, const const_iterator1_type &it1, const const_iterator2_type &it2): container_const_reference<self_type> (vbs), it1_ (it1), it2_ (it2) {} // Arithmetic BOOST_UBLAS_INLINE const_iterator &operator ++ () { ++ it2_; return *this; } BOOST_UBLAS_INLINE const_iterator &operator -- () { -- it2_; return *this; } BOOST_UBLAS_INLINE const_iterator &operator += (difference_type n) { it2_ += n; return *this; } BOOST_UBLAS_INLINE const_iterator &operator -= (difference_type n) { it2_ -= n; return *this; } BOOST_UBLAS_INLINE difference_type operator - (const const_iterator &it) const { BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ()); // FIXME: we shouldn't compare floats // BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ()); return it2_ - it.it2_; } // Dereference BOOST_UBLAS_INLINE const_reference operator * () const { return functor_type::apply (it1_, *it2_); } // Index BOOST_UBLAS_INLINE size_type index () const { return it2_.index (); } // Assignment BOOST_UBLAS_INLINE const_iterator &operator = (const const_iterator &it) { container_const_reference<self_type>::assign (&it ()); it1_ = it.it1_; it2_ = it.it2_; return *this; } // Comparison BOOST_UBLAS_INLINE bool operator == (const const_iterator &it) const { BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ()); // FIXME: we shouldn't compare floats // BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ()); return it2_ == it.it2_; } BOOST_UBLAS_INLINE bool operator < (const const_iterator &it) const { BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ()); // FIXME: we shouldn't compare floats // BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ()); return it2_ < it.it2_; } private: const_iterator1_type it1_; const_iterator2_type it2_; };
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -