📄 symmetric.hpp
字号:
BOOST_UBLAS_CHECK (it1_ != it1_end_, internal_logic ()); ++ it1_; if (it1_ == it1_end_ && end_ == 1) { it2_ = it2_begin_; current_ = 1; } } else /* if (current_ == 1) */ { BOOST_UBLAS_CHECK (it2_ != it2_end_, internal_logic ()); ++ it2_; if (it2_ == it2_end_ && end_ == 0) { it1_ = it1_begin_; current_ = 0; } } return *this; } BOOST_UBLAS_INLINE const_iterator1 &operator -- () { BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ()); if (current_ == 0) { if (it1_ == it1_begin_ && begin_ == 1) { it2_ = it2_end_; BOOST_UBLAS_CHECK (it2_ != it2_begin_, internal_logic ()); -- it2_; current_ = 1; } else { -- it1_; } } else /* if (current_ == 1) */ { if (it2_ == it2_begin_ && begin_ == 0) { it1_ = it1_end_; BOOST_UBLAS_CHECK (it1_ != it1_begin_, internal_logic ()); -- it1_; current_ = 0; } else { -- it2_; } } return *this; } BOOST_UBLAS_INLINE const_iterator1 &operator += (difference_type n) { BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ()); if (current_ == 0) { size_type d = (std::min) (n, it1_end_ - it1_); it1_ += d; n -= d; if (n > 0 || (end_ == 1 && it1_ == it1_end_)) { BOOST_UBLAS_CHECK (end_ == 1, external_logic ()); d = (std::min) (n, it2_end_ - it2_begin_); it2_ = it2_begin_ + d; n -= d; current_ = 1; } } else /* if (current_ == 1) */ { size_type d = (std::min) (n, it2_end_ - it2_); it2_ += d; n -= d; if (n > 0 || (end_ == 0 && it2_ == it2_end_)) { BOOST_UBLAS_CHECK (end_ == 0, external_logic ()); d = (std::min) (n, it1_end_ - it1_begin_); it1_ = it1_begin_ + d; n -= d; current_ = 0; } } BOOST_UBLAS_CHECK (n == 0, external_logic ()); return *this; } BOOST_UBLAS_INLINE const_iterator1 &operator -= (difference_type n) { BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ()); if (current_ == 0) { size_type d = (std::min) (n, it1_ - it1_begin_); it1_ -= d; n -= d; if (n > 0) { BOOST_UBLAS_CHECK (end_ == 1, external_logic ()); d = (std::min) (n, it2_end_ - it2_begin_); it2_ = it2_end_ - d; n -= d; current_ = 1; } } else /* if (current_ == 1) */ { size_type d = (std::min) (n, it2_ - it2_begin_); it2_ -= d; n -= d; if (n > 0) { BOOST_UBLAS_CHECK (end_ == 0, external_logic ()); d = (std::min) (n, it1_end_ - it1_begin_); it1_ = it1_end_ - d; n -= d; current_ = 0; } } BOOST_UBLAS_CHECK (n == 0, external_logic ()); return *this; } BOOST_UBLAS_INLINE difference_type operator - (const const_iterator1 &it) const { BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ()); BOOST_UBLAS_CHECK (it.current_ == 0 || it.current_ == 1, internal_logic ()); BOOST_UBLAS_CHECK (/* begin_ == it.begin_ && */ end_ == it.end_, internal_logic ()); if (current_ == 0 && it.current_ == 0) { return it1_ - it.it1_; } else if (current_ == 0 && it.current_ == 1) { if (end_ == 1 && it.end_ == 1) { return (it1_ - it.it1_end_) + (it.it2_begin_ - it.it2_); } else /* if (end_ == 0 && it.end_ == 0) */ { return (it1_ - it.it1_begin_) + (it.it2_end_ - it.it2_); } } else if (current_ == 1 && it.current_ == 0) { if (end_ == 1 && it.end_ == 1) { return (it2_ - it.it2_begin_) + (it.it1_end_ - it.it1_); } else /* if (end_ == 0 && it.end_ == 0) */ { return (it2_ - it.it2_end_) + (it.it1_begin_ - it.it1_); } } else /* if (current_ == 1 && it.current_ == 1) */ { return it2_ - it.it2_; } } // Dereference BOOST_UBLAS_INLINE const_reference operator * () const { BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ()); if (current_ == 0) { BOOST_UBLAS_CHECK (it1_ != it1_end_, internal_logic ()); return *it1_; } else /* if (current_ == 1) */ { BOOST_UBLAS_CHECK (it2_ != it2_end_, internal_logic ()); return *it2_; } }#ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION BOOST_UBLAS_INLINE#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION typename self_type::#endif const_iterator2 begin () const { return (*this) ().find2 (1, index1 (), 0); } BOOST_UBLAS_INLINE#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION typename self_type::#endif const_iterator2 end () const { return (*this) ().find2 (1, index1 (), (*this) ().size2 ()); } BOOST_UBLAS_INLINE#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION typename self_type::#endif const_reverse_iterator2 rbegin () const { return const_reverse_iterator2 (end ()); } BOOST_UBLAS_INLINE#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION typename self_type::#endif const_reverse_iterator2 rend () const { return const_reverse_iterator2 (begin ()); }#endif // Indices BOOST_UBLAS_INLINE size_type index1 () const { BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ()); if (current_ == 0) { BOOST_UBLAS_CHECK (it1_ != it1_end_, internal_logic ()); return it1_.index1 (); } else /* if (current_ == 1) */ { BOOST_UBLAS_CHECK (it2_ != it2_end_, internal_logic ()); return it2_.index2 (); } } BOOST_UBLAS_INLINE size_type index2 () const { BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ()); if (current_ == 0) { BOOST_UBLAS_CHECK (it1_ != it1_end_, internal_logic ()); return it1_.index2 (); } else /* if (current_ == 1) */ { BOOST_UBLAS_CHECK (it2_ != it2_end_, internal_logic ()); return it2_.index1 (); } } // Assignment BOOST_UBLAS_INLINE const_iterator1 &operator = (const const_iterator1 &it) { container_const_reference<self_type>::assign (&it ()); begin_ = it.begin_; end_ = it.end_; current_ = it.current_; it1_begin_ = it.it1_begin_; it1_end_ = it.it1_end_; it1_ = it.it1_; it2_begin_ = it.it2_begin_; it2_end_ = it.it2_end_; it2_ = it.it2_; return *this; } // Comparison BOOST_UBLAS_INLINE bool operator == (const const_iterator1 &it) const { BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ()); BOOST_UBLAS_CHECK (it.current_ == 0 || it.current_ == 1, internal_logic ()); BOOST_UBLAS_CHECK (/* begin_ == it.begin_ && */ end_ == it.end_, internal_logic ()); return (current_ == 0 && it.current_ == 0 && it1_ == it.it1_) || (current_ == 1 && it.current_ == 1 && it2_ == it.it2_); } BOOST_UBLAS_INLINE bool operator < (const const_iterator1 &it) const { BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); return it - *this > 0; } private: int begin_; int end_; int current_; const_iterator1_type it1_begin_; const_iterator1_type it1_end_; const_iterator1_type it1_; const_iterator2_type it2_begin_; const_iterator2_type it2_end_; const_iterator2_type it2_; };#endif BOOST_UBLAS_INLINE const_iterator1 begin1 () const { return find1 (0, 0, 0); } BOOST_UBLAS_INLINE const_iterator1 end1 () const { return find1 (0, size1 (), 0); }#ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR class iterator1: public container_reference<symmetric_adaptor>, public random_access_iterator_base<packed_random_access_iterator_tag, iterator1, value_type> { public:#ifndef BOOST_MSVC_STD_ITERATOR typedef typename iterator_restrict_traits<typename iterator1_type::iterator_category, packed_random_access_iterator_tag>::iterator_category iterator_category; typedef typename iterator1_type::value_type value_type; typedef typename iterator1_type::difference_type difference_type; typedef typename iterator1_type::reference reference; typedef typename iterator1_type::pointer pointer;#else typedef typename iterator_restrict_traits<typename M::iterator1::iterator_category, packed_random_access_iterator_tag>::iterator_category iterator_category;#endif typedef iterator2 dual_iterator_type; typedef reverse_iterator2 dual_reverse_iterator_type; // Construction and destruction BOOST_UBLAS_INLINE iterator1 (): container_reference<self_type> (), it1_ () {} BOOST_UBLAS_INLINE iterator1 (self_type &m, const iterator1_type &it1): container_reference<self_type> (m), it1_ (it1) {} // Arithmetic BOOST_UBLAS_INLINE iterator1 &operator ++ () { ++ it1_; return *this; } BOOST_UBLAS_INLINE iterator1 &operator -- () { -- it1_; return *this; } BOOST_UBLAS_INLINE iterator1 &operator += (difference_type n) { it1_ += n; return *this; } BOOST_UBLAS_INLINE iterator1 &operator -= (difference_type n) { it1_ -= n; return *this; } BOOST_UBLAS_INLINE difference_type operator - (const iterator1 &it) const { BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); return it1_ - it.it1_; } // Dereference BOOST_UBLAS_INLINE reference operator * () const { return *it1_; }#ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION BOOST_UBLAS_INLINE#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION typename self_type::#endif iterator2 begin () const { return (*this) ().find2 (1, index1 (), 0); } BOOST_UBLAS_INLINE#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION typename self_type::#endif iterator2 end () const { return (*this) ().find2 (1, index1 (), (*this) ().size2 ()); } BOO
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -