sl@0: // sl@0: // Copyright (c) 2000-2002 sl@0: // Joerg Walter, Mathias Koch sl@0: // sl@0: // Permission to use, copy, modify, distribute and sell this software sl@0: // and its documentation for any purpose is hereby granted without fee, sl@0: // provided that the above copyright notice appear in all copies and sl@0: // that both that copyright notice and this permission notice appear sl@0: // in supporting documentation. The authors make no representations sl@0: // about the suitability of this software for any purpose. sl@0: // It is provided "as is" without express or implied warranty. sl@0: // sl@0: // The authors gratefully acknowledge the support of sl@0: // GeNeSys mbH & Co. KG in producing this work. sl@0: // sl@0: sl@0: #ifndef _BOOST_UBLAS_SYMMETRIC_ sl@0: #define _BOOST_UBLAS_SYMMETRIC_ sl@0: sl@0: #include sl@0: #include sl@0: sl@0: // Iterators based on ideas of Jeremy Siek sl@0: // Symmetric matrices are square. Thanks to Peter Schmitteckert for spotting this. sl@0: sl@0: namespace boost { namespace numeric { namespace ublas { sl@0: sl@0: template sl@0: bool is_symmetric (const M &m) { sl@0: typedef typename M::size_type size_type; sl@0: sl@0: if (m.size1 () != m.size2 ()) sl@0: return false; sl@0: size_type size = BOOST_UBLAS_SAME (m.size1 (), m.size2 ()); sl@0: for (size_type i = 0; i < size; ++ i) { sl@0: for (size_type j = i; j < size; ++ j) { sl@0: if (m (i, j) != m (j, i)) sl@0: return false; sl@0: } sl@0: } sl@0: return true; sl@0: } sl@0: sl@0: // Array based symmetric matrix class sl@0: template sl@0: class symmetric_matrix: sl@0: public matrix_container > { sl@0: sl@0: typedef T *pointer; sl@0: typedef TRI triangular_type; sl@0: typedef L layout_type; sl@0: typedef symmetric_matrix self_type; sl@0: public: sl@0: #ifdef BOOST_UBLAS_ENABLE_PROXY_SHORTCUTS sl@0: using matrix_container::operator (); sl@0: #endif sl@0: typedef typename A::size_type size_type; sl@0: typedef typename A::difference_type difference_type; sl@0: typedef T value_type; sl@0: typedef const T &const_reference; sl@0: typedef T &reference; sl@0: typedef A array_type; sl@0: sl@0: typedef const matrix_reference const_closure_type; sl@0: typedef matrix_reference closure_type; sl@0: typedef vector vector_temporary_type; sl@0: typedef matrix matrix_temporary_type; // general sub-matrix sl@0: typedef packed_tag storage_category; sl@0: typedef typename L::orientation_category orientation_category; sl@0: sl@0: // Construction and destruction sl@0: BOOST_UBLAS_INLINE sl@0: symmetric_matrix (): sl@0: matrix_container (), sl@0: size_ (0), data_ (0) {} sl@0: BOOST_UBLAS_INLINE sl@0: symmetric_matrix (size_type size): sl@0: matrix_container (), sl@0: size_ (BOOST_UBLAS_SAME (size, size)), data_ (triangular_type::packed_size (layout_type (), size, size)) { sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: symmetric_matrix (size_type size1, size_type size2): sl@0: matrix_container (), sl@0: size_ (BOOST_UBLAS_SAME (size1, size2)), data_ (triangular_type::packed_size (layout_type (), size1, size2)) { sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: symmetric_matrix (size_type size, const array_type &data): sl@0: matrix_container (), sl@0: size_ (size), data_ (data) {} sl@0: BOOST_UBLAS_INLINE sl@0: symmetric_matrix (const symmetric_matrix &m): sl@0: matrix_container (), sl@0: size_ (m.size_), data_ (m.data_) {} sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: symmetric_matrix (const matrix_expression &ae): sl@0: matrix_container (), sl@0: size_ (BOOST_UBLAS_SAME (ae ().size1 (), ae ().size2 ())), sl@0: data_ (triangular_type::packed_size (layout_type (), size_, size_)) { sl@0: matrix_assign (*this, ae); sl@0: } sl@0: sl@0: // Accessors sl@0: BOOST_UBLAS_INLINE sl@0: size_type size1 () const { sl@0: return size_; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: size_type size2 () const { sl@0: return size_; sl@0: } sl@0: sl@0: // Storage accessors sl@0: BOOST_UBLAS_INLINE sl@0: const array_type &data () const { sl@0: return data_; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: array_type &data () { sl@0: return data_; sl@0: } sl@0: sl@0: // Resizing sl@0: BOOST_UBLAS_INLINE sl@0: void resize (size_type size, bool preserve = true) { sl@0: if (preserve) { sl@0: self_type temporary (size, size); sl@0: detail::matrix_resize_preserve (*this, temporary); sl@0: } sl@0: else { sl@0: data ().resize (triangular_type::packed_size (layout_type (), size, size)); sl@0: size_ = size; sl@0: } sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: void resize (size_type size1, size_type size2, bool preserve = true) { sl@0: resize (BOOST_UBLAS_SAME (size1, size2), preserve); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: void resize_packed_preserve (size_type size) { sl@0: size_ = BOOST_UBLAS_SAME (size, size); sl@0: data ().resize (triangular_type::packed_size (layout_type (), size_, size_), value_type ()); sl@0: } sl@0: sl@0: // Element access sl@0: BOOST_UBLAS_INLINE sl@0: const_reference operator () (size_type i, size_type j) const { sl@0: BOOST_UBLAS_CHECK (i < size_, bad_index ()); sl@0: BOOST_UBLAS_CHECK (j < size_, bad_index ()); sl@0: if (triangular_type::other (i, j)) sl@0: return data () [triangular_type::element (layout_type (), i, size_, j, size_)]; sl@0: else sl@0: return data () [triangular_type::element (layout_type (), j, size_, i, size_)]; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: reference at_element (size_type i, size_type j) { sl@0: BOOST_UBLAS_CHECK (i < size_, bad_index ()); sl@0: BOOST_UBLAS_CHECK (j < size_, bad_index ()); sl@0: return data () [triangular_type::element (layout_type (), i, size_, j, size_)]; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: reference operator () (size_type i, size_type j) { sl@0: BOOST_UBLAS_CHECK (i < size_, bad_index ()); sl@0: BOOST_UBLAS_CHECK (j < size_, bad_index ()); sl@0: if (triangular_type::other (i, j)) sl@0: return data () [triangular_type::element (layout_type (), i, size_, j, size_)]; sl@0: else sl@0: return data () [triangular_type::element (layout_type (), j, size_, i, size_)]; sl@0: } sl@0: sl@0: // Element assignment sl@0: BOOST_UBLAS_INLINE sl@0: reference insert_element (size_type i, size_type j, const_reference t) { sl@0: return (operator () (i, j) = t); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: void erase_element (size_type i, size_type j) { sl@0: operator () (i, j) = value_type/*zero*/(); sl@0: } sl@0: sl@0: // Zeroing sl@0: BOOST_UBLAS_INLINE sl@0: void clear () { sl@0: // data ().clear (); sl@0: std::fill (data ().begin (), data ().end (), value_type/*zero*/()); sl@0: } sl@0: sl@0: // Assignment sl@0: BOOST_UBLAS_INLINE sl@0: symmetric_matrix &operator = (const symmetric_matrix &m) { sl@0: size_ = m.size_; sl@0: data () = m.data (); sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: symmetric_matrix &assign_temporary (symmetric_matrix &m) { sl@0: swap (m); sl@0: return *this; sl@0: } sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: symmetric_matrix &operator = (const matrix_expression &ae) { sl@0: self_type temporary (ae); sl@0: return assign_temporary (temporary); sl@0: } sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: symmetric_matrix &assign (const matrix_expression &ae) { sl@0: matrix_assign (*this, ae); sl@0: return *this; sl@0: } sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: symmetric_matrix& operator += (const matrix_expression &ae) { sl@0: self_type temporary (*this + ae); sl@0: return assign_temporary (temporary); sl@0: } sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: symmetric_matrix &plus_assign (const matrix_expression &ae) { sl@0: matrix_assign (*this, ae); sl@0: return *this; sl@0: } sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: symmetric_matrix& operator -= (const matrix_expression &ae) { sl@0: self_type temporary (*this - ae); sl@0: return assign_temporary (temporary); sl@0: } sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: symmetric_matrix &minus_assign (const matrix_expression &ae) { sl@0: matrix_assign (*this, ae); sl@0: return *this; sl@0: } sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: symmetric_matrix& operator *= (const AT &at) { sl@0: matrix_assign_scalar (*this, at); sl@0: return *this; sl@0: } sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: symmetric_matrix& operator /= (const AT &at) { sl@0: matrix_assign_scalar (*this, at); sl@0: return *this; sl@0: } sl@0: sl@0: // Swapping sl@0: BOOST_UBLAS_INLINE sl@0: void swap (symmetric_matrix &m) { sl@0: if (this != &m) { sl@0: std::swap (size_, m.size_); sl@0: data ().swap (m.data ()); sl@0: } sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: friend void swap (symmetric_matrix &m1, symmetric_matrix &m2) { sl@0: m1.swap (m2); sl@0: } sl@0: sl@0: // Iterator types sl@0: #ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR sl@0: typedef indexed_iterator1 iterator1; sl@0: typedef indexed_iterator2 iterator2; sl@0: typedef indexed_const_iterator1 const_iterator1; sl@0: typedef indexed_const_iterator2 const_iterator2; sl@0: #else sl@0: class const_iterator1; sl@0: class iterator1; sl@0: class const_iterator2; sl@0: class iterator2; sl@0: #endif sl@0: typedef reverse_iterator_base1 const_reverse_iterator1; sl@0: typedef reverse_iterator_base1 reverse_iterator1; sl@0: typedef reverse_iterator_base2 const_reverse_iterator2; sl@0: typedef reverse_iterator_base2 reverse_iterator2; sl@0: sl@0: // Element lookup sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator1 find1 (int /* rank */, size_type i, size_type j) const { sl@0: return const_iterator1 (*this, i, j); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: iterator1 find1 (int rank, size_type i, size_type j) { sl@0: if (rank == 1) sl@0: i = triangular_type::mutable_restrict1 (i, j); sl@0: return iterator1 (*this, i, j); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator2 find2 (int /* rank */, size_type i, size_type j) const { sl@0: return const_iterator2 (*this, i, j); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: iterator2 find2 (int rank, size_type i, size_type j) { sl@0: if (rank == 1) sl@0: j = triangular_type::mutable_restrict2 (i, j); sl@0: return iterator2 (*this, i, j); sl@0: } sl@0: sl@0: // Iterators simply are indices. sl@0: sl@0: #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR sl@0: class const_iterator1: sl@0: public container_const_reference, sl@0: public random_access_iterator_base { sl@0: public: sl@0: typedef typename symmetric_matrix::value_type value_type; sl@0: typedef typename symmetric_matrix::difference_type difference_type; sl@0: typedef typename symmetric_matrix::const_reference reference; sl@0: typedef const typename symmetric_matrix::pointer pointer; sl@0: sl@0: typedef const_iterator2 dual_iterator_type; sl@0: typedef const_reverse_iterator2 dual_reverse_iterator_type; sl@0: sl@0: // Construction and destruction sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator1 (): sl@0: container_const_reference (), it1_ (), it2_ () {} sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator1 (const self_type &m, size_type it1, size_type it2): sl@0: container_const_reference (m), it1_ (it1), it2_ (it2) {} sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator1 (const iterator1 &it): sl@0: container_const_reference (it ()), it1_ (it.it1_), it2_ (it.it2_) {} sl@0: sl@0: // Arithmetic sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator1 &operator ++ () { sl@0: ++ it1_; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator1 &operator -- () { sl@0: -- it1_; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator1 &operator += (difference_type n) { sl@0: it1_ += n; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator1 &operator -= (difference_type n) { sl@0: it1_ -= n; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: difference_type operator - (const const_iterator1 &it) const { sl@0: BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); sl@0: BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ()); sl@0: return it1_ - it.it1_; sl@0: } sl@0: sl@0: // Dereference sl@0: BOOST_UBLAS_INLINE sl@0: const_reference operator * () const { sl@0: return (*this) () (it1_, it2_); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_reference operator [] (difference_type n) const { sl@0: return *(*this + n); sl@0: } sl@0: sl@0: #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: const_iterator2 begin () const { sl@0: return (*this) ().find2 (1, it1_, 0); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: const_iterator2 end () const { sl@0: return (*this) ().find2 (1, it1_, (*this) ().size2 ()); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: const_reverse_iterator2 rbegin () const { sl@0: return const_reverse_iterator2 (end ()); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: const_reverse_iterator2 rend () const { sl@0: return const_reverse_iterator2 (begin ()); sl@0: } sl@0: #endif sl@0: sl@0: // Indices sl@0: BOOST_UBLAS_INLINE sl@0: size_type index1 () const { sl@0: return it1_; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: size_type index2 () const { sl@0: return it2_; sl@0: } sl@0: sl@0: // Assignment sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator1 &operator = (const const_iterator1 &it) { sl@0: container_const_reference::assign (&it ()); sl@0: it1_ = it.it1_; sl@0: it2_ = it.it2_; sl@0: return *this; sl@0: } sl@0: sl@0: // Comparison sl@0: BOOST_UBLAS_INLINE sl@0: bool operator == (const const_iterator1 &it) const { sl@0: BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); sl@0: BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ()); sl@0: return it1_ == it.it1_; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: bool operator < (const const_iterator1 &it) const { sl@0: BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); sl@0: BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ()); sl@0: return it1_ < it.it1_; sl@0: } sl@0: sl@0: private: sl@0: size_type it1_; sl@0: size_type it2_; sl@0: }; sl@0: #endif sl@0: sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator1 begin1 () const { sl@0: return find1 (0, 0, 0); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator1 end1 () const { sl@0: return find1 (0, size_, 0); sl@0: } sl@0: sl@0: #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR sl@0: class iterator1: sl@0: public container_reference, sl@0: public random_access_iterator_base { sl@0: public: sl@0: typedef typename symmetric_matrix::value_type value_type; sl@0: typedef typename symmetric_matrix::difference_type difference_type; sl@0: typedef typename symmetric_matrix::reference reference; sl@0: typedef typename symmetric_matrix::pointer pointer; sl@0: typedef iterator2 dual_iterator_type; sl@0: typedef reverse_iterator2 dual_reverse_iterator_type; sl@0: sl@0: // Construction and destruction sl@0: BOOST_UBLAS_INLINE sl@0: iterator1 (): sl@0: container_reference (), it1_ (), it2_ () {} sl@0: BOOST_UBLAS_INLINE sl@0: iterator1 (self_type &m, size_type it1, size_type it2): sl@0: container_reference (m), it1_ (it1), it2_ (it2) {} sl@0: sl@0: // Arithmetic sl@0: BOOST_UBLAS_INLINE sl@0: iterator1 &operator ++ () { sl@0: ++ it1_; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: iterator1 &operator -- () { sl@0: -- it1_; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: iterator1 &operator += (difference_type n) { sl@0: it1_ += n; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: iterator1 &operator -= (difference_type n) { sl@0: it1_ -= n; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: difference_type operator - (const iterator1 &it) const { sl@0: BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); sl@0: BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ()); sl@0: return it1_ - it.it1_; sl@0: } sl@0: sl@0: // Dereference sl@0: BOOST_UBLAS_INLINE sl@0: reference operator * () const { sl@0: return (*this) () (it1_, it2_); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: reference operator [] (difference_type n) const { sl@0: return *(*this + n); sl@0: } sl@0: sl@0: #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: iterator2 begin () const { sl@0: return (*this) ().find2 (1, it1_, 0); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: iterator2 end () const { sl@0: return (*this) ().find2 (1, it1_, (*this) ().size2 ()); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: reverse_iterator2 rbegin () const { sl@0: return reverse_iterator2 (end ()); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: reverse_iterator2 rend () const { sl@0: return reverse_iterator2 (begin ()); sl@0: } sl@0: #endif sl@0: sl@0: // Indices sl@0: BOOST_UBLAS_INLINE sl@0: size_type index1 () const { sl@0: return it1_; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: size_type index2 () const { sl@0: return it2_; sl@0: } sl@0: sl@0: // Assignment sl@0: BOOST_UBLAS_INLINE sl@0: iterator1 &operator = (const iterator1 &it) { sl@0: container_reference::assign (&it ()); sl@0: it1_ = it.it1_; sl@0: it2_ = it.it2_; sl@0: return *this; sl@0: } sl@0: sl@0: // Comparison sl@0: BOOST_UBLAS_INLINE sl@0: bool operator == (const iterator1 &it) const { sl@0: BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); sl@0: BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ()); sl@0: return it1_ == it.it1_; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: bool operator < (const iterator1 &it) const { sl@0: BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); sl@0: BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ()); sl@0: return it1_ < it.it1_; sl@0: } sl@0: sl@0: private: sl@0: size_type it1_; sl@0: size_type it2_; sl@0: sl@0: friend class const_iterator1; sl@0: }; sl@0: #endif sl@0: sl@0: BOOST_UBLAS_INLINE sl@0: iterator1 begin1 () { sl@0: return find1 (0, 0, 0); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: iterator1 end1 () { sl@0: return find1 (0, size_, 0); sl@0: } sl@0: sl@0: #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR sl@0: class const_iterator2: sl@0: public container_const_reference, sl@0: public random_access_iterator_base { sl@0: public: sl@0: typedef typename symmetric_matrix::value_type value_type; sl@0: typedef typename symmetric_matrix::difference_type difference_type; sl@0: typedef typename symmetric_matrix::const_reference reference; sl@0: typedef const typename symmetric_matrix::pointer pointer; sl@0: sl@0: typedef const_iterator1 dual_iterator_type; sl@0: typedef const_reverse_iterator1 dual_reverse_iterator_type; sl@0: sl@0: // Construction and destruction sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator2 (): sl@0: container_const_reference (), it1_ (), it2_ () {} sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator2 (const self_type &m, size_type it1, size_type it2): sl@0: container_const_reference (m), it1_ (it1), it2_ (it2) {} sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator2 (const iterator2 &it): sl@0: container_const_reference (it ()), it1_ (it.it1_), it2_ (it.it2_) {} sl@0: sl@0: // Arithmetic sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator2 &operator ++ () { sl@0: ++ it2_; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator2 &operator -- () { sl@0: -- it2_; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator2 &operator += (difference_type n) { sl@0: it2_ += n; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator2 &operator -= (difference_type n) { sl@0: it2_ -= n; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: difference_type operator - (const const_iterator2 &it) const { sl@0: BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); sl@0: BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ()); sl@0: return it2_ - it.it2_; sl@0: } sl@0: sl@0: // Dereference sl@0: BOOST_UBLAS_INLINE sl@0: const_reference operator * () const { sl@0: return (*this) () (it1_, it2_); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_reference operator [] (difference_type n) const { sl@0: return *(*this + n); sl@0: } sl@0: sl@0: #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: const_iterator1 begin () const { sl@0: return (*this) ().find1 (1, 0, it2_); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: const_iterator1 end () const { sl@0: return (*this) ().find1 (1, (*this) ().size1 (), it2_); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: const_reverse_iterator1 rbegin () const { sl@0: return const_reverse_iterator1 (end ()); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: const_reverse_iterator1 rend () const { sl@0: return const_reverse_iterator1 (begin ()); sl@0: } sl@0: #endif sl@0: sl@0: // Indices sl@0: BOOST_UBLAS_INLINE sl@0: size_type index1 () const { sl@0: return it1_; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: size_type index2 () const { sl@0: return it2_; sl@0: } sl@0: sl@0: // Assignment sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator2 &operator = (const const_iterator2 &it) { sl@0: container_const_reference::assign (&it ()); sl@0: it1_ = it.it1_; sl@0: it2_ = it.it2_; sl@0: return *this; sl@0: } sl@0: sl@0: // Comparison sl@0: BOOST_UBLAS_INLINE sl@0: bool operator == (const const_iterator2 &it) const { sl@0: BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); sl@0: BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ()); sl@0: return it2_ == it.it2_; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: bool operator < (const const_iterator2 &it) const { sl@0: BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); sl@0: BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ()); sl@0: return it2_ < it.it2_; sl@0: } sl@0: sl@0: private: sl@0: size_type it1_; sl@0: size_type it2_; sl@0: }; sl@0: #endif sl@0: sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator2 begin2 () const { sl@0: return find2 (0, 0, 0); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator2 end2 () const { sl@0: return find2 (0, 0, size_); sl@0: } sl@0: sl@0: #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR sl@0: class iterator2: sl@0: public container_reference, sl@0: public random_access_iterator_base { sl@0: public: sl@0: typedef typename symmetric_matrix::value_type value_type; sl@0: typedef typename symmetric_matrix::difference_type difference_type; sl@0: typedef typename symmetric_matrix::reference reference; sl@0: typedef typename symmetric_matrix::pointer pointer; sl@0: sl@0: typedef iterator1 dual_iterator_type; sl@0: typedef reverse_iterator1 dual_reverse_iterator_type; sl@0: sl@0: // Construction and destruction sl@0: BOOST_UBLAS_INLINE sl@0: iterator2 (): sl@0: container_reference (), it1_ (), it2_ () {} sl@0: BOOST_UBLAS_INLINE sl@0: iterator2 (self_type &m, size_type it1, size_type it2): sl@0: container_reference (m), it1_ (it1), it2_ (it2) {} sl@0: sl@0: // Arithmetic sl@0: BOOST_UBLAS_INLINE sl@0: iterator2 &operator ++ () { sl@0: ++ it2_; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: iterator2 &operator -- () { sl@0: -- it2_; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: iterator2 &operator += (difference_type n) { sl@0: it2_ += n; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: iterator2 &operator -= (difference_type n) { sl@0: it2_ -= n; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: difference_type operator - (const iterator2 &it) const { sl@0: BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); sl@0: BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ()); sl@0: return it2_ - it.it2_; sl@0: } sl@0: sl@0: // Dereference sl@0: BOOST_UBLAS_INLINE sl@0: reference operator * () const { sl@0: return (*this) () (it1_, it2_); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: reference operator [] (difference_type n) const { sl@0: return *(*this + n); sl@0: } sl@0: sl@0: #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: iterator1 begin () const { sl@0: return (*this) ().find1 (1, 0, it2_); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: iterator1 end () const { sl@0: return (*this) ().find1 (1, (*this) ().size1 (), it2_); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: reverse_iterator1 rbegin () const { sl@0: return reverse_iterator1 (end ()); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: reverse_iterator1 rend () const { sl@0: return reverse_iterator1 (begin ()); sl@0: } sl@0: #endif sl@0: sl@0: // Indices sl@0: BOOST_UBLAS_INLINE sl@0: size_type index1 () const { sl@0: return it1_; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: size_type index2 () const { sl@0: return it2_; sl@0: } sl@0: sl@0: // Assignment sl@0: BOOST_UBLAS_INLINE sl@0: iterator2 &operator = (const iterator2 &it) { sl@0: container_reference::assign (&it ()); sl@0: it1_ = it.it1_; sl@0: it2_ = it.it2_; sl@0: return *this; sl@0: } sl@0: sl@0: // Comparison sl@0: BOOST_UBLAS_INLINE sl@0: bool operator == (const iterator2 &it) const { sl@0: BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); sl@0: BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ()); sl@0: return it2_ == it.it2_; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: bool operator < (const iterator2 &it) const { sl@0: BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); sl@0: BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ()); sl@0: return it2_ < it.it2_; sl@0: } sl@0: sl@0: private: sl@0: size_type it1_; sl@0: size_type it2_; sl@0: sl@0: friend class const_iterator2; sl@0: }; sl@0: #endif sl@0: sl@0: BOOST_UBLAS_INLINE sl@0: iterator2 begin2 () { sl@0: return find2 (0, 0, 0); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: iterator2 end2 () { sl@0: return find2 (0, 0, size_); sl@0: } sl@0: sl@0: // Reverse iterators sl@0: sl@0: BOOST_UBLAS_INLINE sl@0: const_reverse_iterator1 rbegin1 () const { sl@0: return const_reverse_iterator1 (end1 ()); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_reverse_iterator1 rend1 () const { sl@0: return const_reverse_iterator1 (begin1 ()); sl@0: } sl@0: sl@0: BOOST_UBLAS_INLINE sl@0: reverse_iterator1 rbegin1 () { sl@0: return reverse_iterator1 (end1 ()); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: reverse_iterator1 rend1 () { sl@0: return reverse_iterator1 (begin1 ()); sl@0: } sl@0: sl@0: BOOST_UBLAS_INLINE sl@0: const_reverse_iterator2 rbegin2 () const { sl@0: return const_reverse_iterator2 (end2 ()); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_reverse_iterator2 rend2 () const { sl@0: return const_reverse_iterator2 (begin2 ()); sl@0: } sl@0: sl@0: BOOST_UBLAS_INLINE sl@0: reverse_iterator2 rbegin2 () { sl@0: return reverse_iterator2 (end2 ()); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: reverse_iterator2 rend2 () { sl@0: return reverse_iterator2 (begin2 ()); sl@0: } sl@0: sl@0: private: sl@0: size_type size_; sl@0: array_type data_; sl@0: }; sl@0: sl@0: sl@0: // Symmetric matrix adaptor class sl@0: template sl@0: class symmetric_adaptor: sl@0: public matrix_expression > { sl@0: sl@0: typedef symmetric_adaptor self_type; sl@0: public: sl@0: #ifdef BOOST_UBLAS_ENABLE_PROXY_SHORTCUTS sl@0: using matrix_expression::operator (); sl@0: #endif sl@0: typedef const M const_matrix_type; sl@0: typedef M matrix_type; sl@0: typedef TRI triangular_type; sl@0: typedef typename M::size_type size_type; sl@0: typedef typename M::difference_type difference_type; sl@0: typedef typename M::value_type value_type; sl@0: typedef typename M::const_reference const_reference; sl@0: typedef typename boost::mpl::if_, sl@0: typename M::const_reference, sl@0: typename M::reference>::type reference; sl@0: typedef typename boost::mpl::if_, sl@0: typename M::const_closure_type, sl@0: typename M::closure_type>::type matrix_closure_type; sl@0: typedef const self_type const_closure_type; sl@0: typedef self_type closure_type; sl@0: // Replaced by _temporary_traits to avoid type requirements on M sl@0: //typedef typename M::vector_temporary_type vector_temporary_type; sl@0: //typedef typename M::matrix_temporary_type matrix_temporary_type; sl@0: typedef typename storage_restrict_traits::storage_category storage_category; sl@0: typedef typename M::orientation_category orientation_category; sl@0: sl@0: // Construction and destruction sl@0: BOOST_UBLAS_INLINE sl@0: symmetric_adaptor (matrix_type &data): sl@0: matrix_expression (), sl@0: data_ (data) { sl@0: BOOST_UBLAS_CHECK (data_.size1 () == data_.size2 (), bad_size ()); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: symmetric_adaptor (const symmetric_adaptor &m): sl@0: matrix_expression (), sl@0: data_ (m.data_) { sl@0: BOOST_UBLAS_CHECK (data_.size1 () == data_.size2 (), bad_size ()); sl@0: } sl@0: sl@0: // Accessors sl@0: BOOST_UBLAS_INLINE sl@0: size_type size1 () const { sl@0: return data_.size1 (); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: size_type size2 () const { sl@0: return data_.size2 (); sl@0: } sl@0: sl@0: // Storage accessors sl@0: BOOST_UBLAS_INLINE sl@0: const matrix_closure_type &data () const { sl@0: return data_; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: matrix_closure_type &data () { sl@0: return data_; sl@0: } sl@0: sl@0: // Element access sl@0: #ifndef BOOST_UBLAS_PROXY_CONST_MEMBER sl@0: BOOST_UBLAS_INLINE sl@0: const_reference operator () (size_type i, size_type j) const { sl@0: BOOST_UBLAS_CHECK (i < size1 (), bad_index ()); sl@0: BOOST_UBLAS_CHECK (j < size2 (), bad_index ()); sl@0: if (triangular_type::other (i, j)) sl@0: return data () (i, j); sl@0: else sl@0: return data () (j, i); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: reference operator () (size_type i, size_type j) { sl@0: BOOST_UBLAS_CHECK (i < size1 (), bad_index ()); sl@0: BOOST_UBLAS_CHECK (j < size2 (), bad_index ()); sl@0: if (triangular_type::other (i, j)) sl@0: return data () (i, j); sl@0: else sl@0: return data () (j, i); sl@0: } sl@0: #else sl@0: BOOST_UBLAS_INLINE sl@0: reference operator () (size_type i, size_type j) const { sl@0: BOOST_UBLAS_CHECK (i < size1 (), bad_index ()); sl@0: BOOST_UBLAS_CHECK (j < size2 (), bad_index ()); sl@0: if (triangular_type::other (i, j)) sl@0: return data () (i, j); sl@0: else sl@0: return data () (j, i); sl@0: } sl@0: #endif sl@0: sl@0: // Assignment sl@0: BOOST_UBLAS_INLINE sl@0: symmetric_adaptor &operator = (const symmetric_adaptor &m) { sl@0: matrix_assign (*this, m); sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: symmetric_adaptor &assign_temporary (symmetric_adaptor &m) { sl@0: *this = m; sl@0: return *this; sl@0: } sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: symmetric_adaptor &operator = (const matrix_expression &ae) { sl@0: matrix_assign (*this, matrix (ae)); sl@0: return *this; sl@0: } sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: symmetric_adaptor &assign (const matrix_expression &ae) { sl@0: matrix_assign (*this, ae); sl@0: return *this; sl@0: } sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: symmetric_adaptor& operator += (const matrix_expression &ae) { sl@0: matrix_assign (*this, matrix (*this + ae)); sl@0: return *this; sl@0: } sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: symmetric_adaptor &plus_assign (const matrix_expression &ae) { sl@0: matrix_assign (*this, ae); sl@0: return *this; sl@0: } sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: symmetric_adaptor& operator -= (const matrix_expression &ae) { sl@0: matrix_assign (*this, matrix (*this - ae)); sl@0: return *this; sl@0: } sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: symmetric_adaptor &minus_assign (const matrix_expression &ae) { sl@0: matrix_assign (*this, ae); sl@0: return *this; sl@0: } sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: symmetric_adaptor& operator *= (const AT &at) { sl@0: matrix_assign_scalar (*this, at); sl@0: return *this; sl@0: } sl@0: template sl@0: BOOST_UBLAS_INLINE sl@0: symmetric_adaptor& operator /= (const AT &at) { sl@0: matrix_assign_scalar (*this, at); sl@0: return *this; sl@0: } sl@0: sl@0: // Closure comparison sl@0: BOOST_UBLAS_INLINE sl@0: bool same_closure (const symmetric_adaptor &sa) const { sl@0: return (*this).data ().same_closure (sa.data ()); sl@0: } sl@0: sl@0: // Swapping sl@0: BOOST_UBLAS_INLINE sl@0: void swap (symmetric_adaptor &m) { sl@0: if (this != &m) sl@0: matrix_swap (*this, m); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: friend void swap (symmetric_adaptor &m1, symmetric_adaptor &m2) { sl@0: m1.swap (m2); sl@0: } sl@0: sl@0: // Iterator types sl@0: private: sl@0: // Use matrix iterator sl@0: typedef typename M::const_iterator1 const_subiterator1_type; sl@0: typedef typename boost::mpl::if_, sl@0: typename M::const_iterator1, sl@0: typename M::iterator1>::type subiterator1_type; sl@0: typedef typename M::const_iterator2 const_subiterator2_type; sl@0: typedef typename boost::mpl::if_, sl@0: typename M::const_iterator2, sl@0: typename M::iterator2>::type subiterator2_type; sl@0: sl@0: public: sl@0: #ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR sl@0: typedef indexed_iterator1 iterator1; sl@0: typedef indexed_iterator2 iterator2; sl@0: typedef indexed_const_iterator1 const_iterator1; sl@0: typedef indexed_const_iterator2 const_iterator2; sl@0: #else sl@0: class const_iterator1; sl@0: class iterator1; sl@0: class const_iterator2; sl@0: class iterator2; sl@0: #endif sl@0: typedef reverse_iterator_base1 const_reverse_iterator1; sl@0: typedef reverse_iterator_base1 reverse_iterator1; sl@0: typedef reverse_iterator_base2 const_reverse_iterator2; sl@0: typedef reverse_iterator_base2 reverse_iterator2; sl@0: sl@0: // Element lookup sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator1 find1 (int rank, size_type i, size_type j) const { sl@0: if (triangular_type::other (i, j)) { sl@0: if (triangular_type::other (size1 (), j)) { sl@0: return const_iterator1 (*this, 0, 0, sl@0: data ().find1 (rank, i, j), data ().find1 (rank, size1 (), j), sl@0: data ().find2 (rank, size2 (), size1 ()), data ().find2 (rank, size2 (), size1 ())); sl@0: } else { sl@0: return const_iterator1 (*this, 0, 1, sl@0: data ().find1 (rank, i, j), data ().find1 (rank, j, j), sl@0: data ().find2 (rank, j, j), data ().find2 (rank, j, size1 ())); sl@0: } sl@0: } else { sl@0: if (triangular_type::other (size1 (), j)) { sl@0: return const_iterator1 (*this, 1, 0, sl@0: data ().find1 (rank, j, j), data ().find1 (rank, size1 (), j), sl@0: data ().find2 (rank, j, i), data ().find2 (rank, j, j)); sl@0: } else { sl@0: return const_iterator1 (*this, 1, 1, sl@0: data ().find1 (rank, size1 (), size2 ()), data ().find1 (rank, size1 (), size2 ()), sl@0: data ().find2 (rank, j, i), data ().find2 (rank, j, size1 ())); sl@0: } sl@0: } sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: iterator1 find1 (int rank, size_type i, size_type j) { sl@0: if (rank == 1) sl@0: i = triangular_type::mutable_restrict1 (i, j); sl@0: return iterator1 (*this, data ().find1 (rank, i, j)); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator2 find2 (int rank, size_type i, size_type j) const { sl@0: if (triangular_type::other (i, j)) { sl@0: if (triangular_type::other (i, size2 ())) { sl@0: return const_iterator2 (*this, 1, 1, sl@0: data ().find1 (rank, size2 (), size1 ()), data ().find1 (rank, size2 (), size1 ()), sl@0: data ().find2 (rank, i, j), data ().find2 (rank, i, size2 ())); sl@0: } else { sl@0: return const_iterator2 (*this, 1, 0, sl@0: data ().find1 (rank, i, i), data ().find1 (rank, size2 (), i), sl@0: data ().find2 (rank, i, j), data ().find2 (rank, i, i)); sl@0: } sl@0: } else { sl@0: if (triangular_type::other (i, size2 ())) { sl@0: return const_iterator2 (*this, 0, 1, sl@0: data ().find1 (rank, j, i), data ().find1 (rank, i, i), sl@0: data ().find2 (rank, i, i), data ().find2 (rank, i, size2 ())); sl@0: } else { sl@0: return const_iterator2 (*this, 0, 0, sl@0: data ().find1 (rank, j, i), data ().find1 (rank, size2 (), i), sl@0: data ().find2 (rank, size1 (), size2 ()), data ().find2 (rank, size2 (), size2 ())); sl@0: } sl@0: } sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: iterator2 find2 (int rank, size_type i, size_type j) { sl@0: if (rank == 1) sl@0: j = triangular_type::mutable_restrict2 (i, j); sl@0: return iterator2 (*this, data ().find2 (rank, i, j)); sl@0: } sl@0: sl@0: // Iterators simply are indices. sl@0: sl@0: #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR sl@0: class const_iterator1: sl@0: public container_const_reference, sl@0: public random_access_iterator_base::iterator_category, sl@0: const_iterator1, value_type> { sl@0: public: sl@0: typedef typename const_subiterator1_type::value_type value_type; sl@0: typedef typename const_subiterator1_type::difference_type difference_type; sl@0: typedef typename const_subiterator1_type::reference reference; sl@0: typedef typename const_subiterator1_type::pointer pointer; sl@0: sl@0: typedef const_iterator2 dual_iterator_type; sl@0: typedef const_reverse_iterator2 dual_reverse_iterator_type; sl@0: sl@0: // Construction and destruction sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator1 (): sl@0: container_const_reference (), sl@0: begin_ (-1), end_ (-1), current_ (-1), sl@0: it1_begin_ (), it1_end_ (), it1_ (), sl@0: it2_begin_ (), it2_end_ (), it2_ () {} sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator1 (const self_type &m, int begin, int end, sl@0: const const_subiterator1_type &it1_begin, const const_subiterator1_type &it1_end, sl@0: const const_subiterator2_type &it2_begin, const const_subiterator2_type &it2_end): sl@0: container_const_reference (m), sl@0: begin_ (begin), end_ (end), current_ (begin), sl@0: it1_begin_ (it1_begin), it1_end_ (it1_end), it1_ (it1_begin_), sl@0: it2_begin_ (it2_begin), it2_end_ (it2_end), it2_ (it2_begin_) { sl@0: if (current_ == 0 && it1_ == it1_end_) sl@0: current_ = 1; sl@0: if (current_ == 1 && it2_ == it2_end_) sl@0: current_ = 0; sl@0: if ((current_ == 0 && it1_ == it1_end_) || sl@0: (current_ == 1 && it2_ == it2_end_)) sl@0: current_ = end_; sl@0: BOOST_UBLAS_CHECK (current_ == end_ || sl@0: (current_ == 0 && it1_ != it1_end_) || sl@0: (current_ == 1 && it2_ != it2_end_), internal_logic ()); sl@0: } sl@0: // FIXME cannot compile sl@0: // iterator1 does not have these members! sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator1 (const iterator1 &it): sl@0: container_const_reference (it ()), sl@0: begin_ (it.begin_), end_ (it.end_), current_ (it.current_), sl@0: it1_begin_ (it.it1_begin_), it1_end_ (it.it1_end_), it1_ (it.it1_), sl@0: it2_begin_ (it.it2_begin_), it2_end_ (it.it2_end_), it2_ (it.it2_) { sl@0: BOOST_UBLAS_CHECK (current_ == end_ || sl@0: (current_ == 0 && it1_ != it1_end_) || sl@0: (current_ == 1 && it2_ != it2_end_), internal_logic ()); sl@0: } sl@0: sl@0: // Arithmetic sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator1 &operator ++ () { sl@0: BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ()); sl@0: if (current_ == 0) { sl@0: BOOST_UBLAS_CHECK (it1_ != it1_end_, internal_logic ()); sl@0: ++ it1_; sl@0: if (it1_ == it1_end_ && end_ == 1) { sl@0: it2_ = it2_begin_; sl@0: current_ = 1; sl@0: } sl@0: } else /* if (current_ == 1) */ { sl@0: BOOST_UBLAS_CHECK (it2_ != it2_end_, internal_logic ()); sl@0: ++ it2_; sl@0: if (it2_ == it2_end_ && end_ == 0) { sl@0: it1_ = it1_begin_; sl@0: current_ = 0; sl@0: } sl@0: } sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator1 &operator -- () { sl@0: BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ()); sl@0: if (current_ == 0) { sl@0: if (it1_ == it1_begin_ && begin_ == 1) { sl@0: it2_ = it2_end_; sl@0: BOOST_UBLAS_CHECK (it2_ != it2_begin_, internal_logic ()); sl@0: -- it2_; sl@0: current_ = 1; sl@0: } else { sl@0: -- it1_; sl@0: } sl@0: } else /* if (current_ == 1) */ { sl@0: if (it2_ == it2_begin_ && begin_ == 0) { sl@0: it1_ = it1_end_; sl@0: BOOST_UBLAS_CHECK (it1_ != it1_begin_, internal_logic ()); sl@0: -- it1_; sl@0: current_ = 0; sl@0: } else { sl@0: -- it2_; sl@0: } sl@0: } sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator1 &operator += (difference_type n) { sl@0: BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ()); sl@0: if (current_ == 0) { sl@0: size_type d = (std::min) (n, it1_end_ - it1_); sl@0: it1_ += d; sl@0: n -= d; sl@0: if (n > 0 || (end_ == 1 && it1_ == it1_end_)) { sl@0: BOOST_UBLAS_CHECK (end_ == 1, external_logic ()); sl@0: d = (std::min) (n, it2_end_ - it2_begin_); sl@0: it2_ = it2_begin_ + d; sl@0: n -= d; sl@0: current_ = 1; sl@0: } sl@0: } else /* if (current_ == 1) */ { sl@0: size_type d = (std::min) (n, it2_end_ - it2_); sl@0: it2_ += d; sl@0: n -= d; sl@0: if (n > 0 || (end_ == 0 && it2_ == it2_end_)) { sl@0: BOOST_UBLAS_CHECK (end_ == 0, external_logic ()); sl@0: d = (std::min) (n, it1_end_ - it1_begin_); sl@0: it1_ = it1_begin_ + d; sl@0: n -= d; sl@0: current_ = 0; sl@0: } sl@0: } sl@0: BOOST_UBLAS_CHECK (n == 0, external_logic ()); sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator1 &operator -= (difference_type n) { sl@0: BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ()); sl@0: if (current_ == 0) { sl@0: size_type d = (std::min) (n, it1_ - it1_begin_); sl@0: it1_ -= d; sl@0: n -= d; sl@0: if (n > 0) { sl@0: BOOST_UBLAS_CHECK (end_ == 1, external_logic ()); sl@0: d = (std::min) (n, it2_end_ - it2_begin_); sl@0: it2_ = it2_end_ - d; sl@0: n -= d; sl@0: current_ = 1; sl@0: } sl@0: } else /* if (current_ == 1) */ { sl@0: size_type d = (std::min) (n, it2_ - it2_begin_); sl@0: it2_ -= d; sl@0: n -= d; sl@0: if (n > 0) { sl@0: BOOST_UBLAS_CHECK (end_ == 0, external_logic ()); sl@0: d = (std::min) (n, it1_end_ - it1_begin_); sl@0: it1_ = it1_end_ - d; sl@0: n -= d; sl@0: current_ = 0; sl@0: } sl@0: } sl@0: BOOST_UBLAS_CHECK (n == 0, external_logic ()); sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: difference_type operator - (const const_iterator1 &it) const { sl@0: BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); sl@0: BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ()); sl@0: BOOST_UBLAS_CHECK (it.current_ == 0 || it.current_ == 1, internal_logic ()); sl@0: BOOST_UBLAS_CHECK (/* begin_ == it.begin_ && */ end_ == it.end_, internal_logic ()); sl@0: if (current_ == 0 && it.current_ == 0) { sl@0: return it1_ - it.it1_; sl@0: } else if (current_ == 0 && it.current_ == 1) { sl@0: if (end_ == 1 && it.end_ == 1) { sl@0: return (it1_ - it.it1_end_) + (it.it2_begin_ - it.it2_); sl@0: } else /* if (end_ == 0 && it.end_ == 0) */ { sl@0: return (it1_ - it.it1_begin_) + (it.it2_end_ - it.it2_); sl@0: } sl@0: sl@0: } else if (current_ == 1 && it.current_ == 0) { sl@0: if (end_ == 1 && it.end_ == 1) { sl@0: return (it2_ - it.it2_begin_) + (it.it1_end_ - it.it1_); sl@0: } else /* if (end_ == 0 && it.end_ == 0) */ { sl@0: return (it2_ - it.it2_end_) + (it.it1_begin_ - it.it1_); sl@0: } sl@0: } sl@0: /* current_ == 1 && it.current_ == 1 */ { sl@0: return it2_ - it.it2_; sl@0: } sl@0: } sl@0: sl@0: // Dereference sl@0: BOOST_UBLAS_INLINE sl@0: const_reference operator * () const { sl@0: BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ()); sl@0: if (current_ == 0) { sl@0: BOOST_UBLAS_CHECK (it1_ != it1_end_, internal_logic ()); sl@0: return *it1_; sl@0: } else /* if (current_ == 1) */ { sl@0: BOOST_UBLAS_CHECK (it2_ != it2_end_, internal_logic ()); sl@0: return *it2_; sl@0: } sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_reference operator [] (difference_type n) const { sl@0: return *(*this + n); sl@0: } sl@0: sl@0: #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: const_iterator2 begin () const { sl@0: return (*this) ().find2 (1, index1 (), 0); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: const_iterator2 end () const { sl@0: return (*this) ().find2 (1, index1 (), (*this) ().size2 ()); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: const_reverse_iterator2 rbegin () const { sl@0: return const_reverse_iterator2 (end ()); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: const_reverse_iterator2 rend () const { sl@0: return const_reverse_iterator2 (begin ()); sl@0: } sl@0: #endif sl@0: sl@0: // Indices sl@0: BOOST_UBLAS_INLINE sl@0: size_type index1 () const { sl@0: BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ()); sl@0: if (current_ == 0) { sl@0: BOOST_UBLAS_CHECK (it1_ != it1_end_, internal_logic ()); sl@0: return it1_.index1 (); sl@0: } else /* if (current_ == 1) */ { sl@0: BOOST_UBLAS_CHECK (it2_ != it2_end_, internal_logic ()); sl@0: return it2_.index2 (); sl@0: } sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: size_type index2 () const { sl@0: BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ()); sl@0: if (current_ == 0) { sl@0: BOOST_UBLAS_CHECK (it1_ != it1_end_, internal_logic ()); sl@0: return it1_.index2 (); sl@0: } else /* if (current_ == 1) */ { sl@0: BOOST_UBLAS_CHECK (it2_ != it2_end_, internal_logic ()); sl@0: return it2_.index1 (); sl@0: } sl@0: } sl@0: sl@0: // Assignment sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator1 &operator = (const const_iterator1 &it) { sl@0: container_const_reference::assign (&it ()); sl@0: begin_ = it.begin_; sl@0: end_ = it.end_; sl@0: current_ = it.current_; sl@0: it1_begin_ = it.it1_begin_; sl@0: it1_end_ = it.it1_end_; sl@0: it1_ = it.it1_; sl@0: it2_begin_ = it.it2_begin_; sl@0: it2_end_ = it.it2_end_; sl@0: it2_ = it.it2_; sl@0: return *this; sl@0: } sl@0: sl@0: // Comparison sl@0: BOOST_UBLAS_INLINE sl@0: bool operator == (const const_iterator1 &it) const { sl@0: BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); sl@0: BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ()); sl@0: BOOST_UBLAS_CHECK (it.current_ == 0 || it.current_ == 1, internal_logic ()); sl@0: BOOST_UBLAS_CHECK (/* begin_ == it.begin_ && */ end_ == it.end_, internal_logic ()); sl@0: return (current_ == 0 && it.current_ == 0 && it1_ == it.it1_) || sl@0: (current_ == 1 && it.current_ == 1 && it2_ == it.it2_); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: bool operator < (const const_iterator1 &it) const { sl@0: BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); sl@0: return it - *this > 0; sl@0: } sl@0: sl@0: private: sl@0: int begin_; sl@0: int end_; sl@0: int current_; sl@0: const_subiterator1_type it1_begin_; sl@0: const_subiterator1_type it1_end_; sl@0: const_subiterator1_type it1_; sl@0: const_subiterator2_type it2_begin_; sl@0: const_subiterator2_type it2_end_; sl@0: const_subiterator2_type it2_; sl@0: }; sl@0: #endif sl@0: sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator1 begin1 () const { sl@0: return find1 (0, 0, 0); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator1 end1 () const { sl@0: return find1 (0, size1 (), 0); sl@0: } sl@0: sl@0: #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR sl@0: class iterator1: sl@0: public container_reference, sl@0: public random_access_iterator_base::iterator_category, sl@0: iterator1, value_type> { sl@0: public: sl@0: typedef typename subiterator1_type::value_type value_type; sl@0: typedef typename subiterator1_type::difference_type difference_type; sl@0: typedef typename subiterator1_type::reference reference; sl@0: typedef typename subiterator1_type::pointer pointer; sl@0: sl@0: typedef iterator2 dual_iterator_type; sl@0: typedef reverse_iterator2 dual_reverse_iterator_type; sl@0: sl@0: // Construction and destruction sl@0: BOOST_UBLAS_INLINE sl@0: iterator1 (): sl@0: container_reference (), it1_ () {} sl@0: BOOST_UBLAS_INLINE sl@0: iterator1 (self_type &m, const subiterator1_type &it1): sl@0: container_reference (m), it1_ (it1) {} sl@0: sl@0: // Arithmetic sl@0: BOOST_UBLAS_INLINE sl@0: iterator1 &operator ++ () { sl@0: ++ it1_; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: iterator1 &operator -- () { sl@0: -- it1_; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: iterator1 &operator += (difference_type n) { sl@0: it1_ += n; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: iterator1 &operator -= (difference_type n) { sl@0: it1_ -= n; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: difference_type operator - (const iterator1 &it) const { sl@0: BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); sl@0: return it1_ - it.it1_; sl@0: } sl@0: sl@0: // Dereference sl@0: BOOST_UBLAS_INLINE sl@0: reference operator * () const { sl@0: return *it1_; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: reference operator [] (difference_type n) const { sl@0: return *(*this + n); sl@0: } sl@0: sl@0: #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: iterator2 begin () const { sl@0: return (*this) ().find2 (1, index1 (), 0); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: iterator2 end () const { sl@0: return (*this) ().find2 (1, index1 (), (*this) ().size2 ()); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: reverse_iterator2 rbegin () const { sl@0: return reverse_iterator2 (end ()); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: reverse_iterator2 rend () const { sl@0: return reverse_iterator2 (begin ()); sl@0: } sl@0: #endif sl@0: sl@0: // Indices sl@0: BOOST_UBLAS_INLINE sl@0: size_type index1 () const { sl@0: return it1_.index1 (); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: size_type index2 () const { sl@0: return it1_.index2 (); sl@0: } sl@0: sl@0: // Assignment sl@0: BOOST_UBLAS_INLINE sl@0: iterator1 &operator = (const iterator1 &it) { sl@0: container_reference::assign (&it ()); sl@0: it1_ = it.it1_; sl@0: return *this; sl@0: } sl@0: sl@0: // Comparison sl@0: BOOST_UBLAS_INLINE sl@0: bool operator == (const iterator1 &it) const { sl@0: BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); sl@0: return it1_ == it.it1_; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: bool operator < (const iterator1 &it) const { sl@0: BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); sl@0: return it1_ < it.it1_; sl@0: } sl@0: sl@0: private: sl@0: subiterator1_type it1_; sl@0: sl@0: friend class const_iterator1; sl@0: }; sl@0: #endif sl@0: sl@0: BOOST_UBLAS_INLINE sl@0: iterator1 begin1 () { sl@0: return find1 (0, 0, 0); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: iterator1 end1 () { sl@0: return find1 (0, size1 (), 0); sl@0: } sl@0: sl@0: #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR sl@0: class const_iterator2: sl@0: public container_const_reference, sl@0: public random_access_iterator_base::iterator_category, sl@0: const_iterator2, value_type> { sl@0: public: sl@0: typedef typename const_subiterator2_type::value_type value_type; sl@0: typedef typename const_subiterator2_type::difference_type difference_type; sl@0: typedef typename const_subiterator2_type::reference reference; sl@0: typedef typename const_subiterator2_type::pointer pointer; sl@0: sl@0: typedef const_iterator1 dual_iterator_type; sl@0: typedef const_reverse_iterator1 dual_reverse_iterator_type; sl@0: sl@0: // Construction and destruction sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator2 (): sl@0: container_const_reference (), sl@0: begin_ (-1), end_ (-1), current_ (-1), sl@0: it1_begin_ (), it1_end_ (), it1_ (), sl@0: it2_begin_ (), it2_end_ (), it2_ () {} sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator2 (const self_type &m, int begin, int end, sl@0: const const_subiterator1_type &it1_begin, const const_subiterator1_type &it1_end, sl@0: const const_subiterator2_type &it2_begin, const const_subiterator2_type &it2_end): sl@0: container_const_reference (m), sl@0: begin_ (begin), end_ (end), current_ (begin), sl@0: it1_begin_ (it1_begin), it1_end_ (it1_end), it1_ (it1_begin_), sl@0: it2_begin_ (it2_begin), it2_end_ (it2_end), it2_ (it2_begin_) { sl@0: if (current_ == 0 && it1_ == it1_end_) sl@0: current_ = 1; sl@0: if (current_ == 1 && it2_ == it2_end_) sl@0: current_ = 0; sl@0: if ((current_ == 0 && it1_ == it1_end_) || sl@0: (current_ == 1 && it2_ == it2_end_)) sl@0: current_ = end_; sl@0: BOOST_UBLAS_CHECK (current_ == end_ || sl@0: (current_ == 0 && it1_ != it1_end_) || sl@0: (current_ == 1 && it2_ != it2_end_), internal_logic ()); sl@0: } sl@0: // FIXME cannot compiler sl@0: // iterator2 does not have these members! sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator2 (const iterator2 &it): sl@0: container_const_reference (it ()), sl@0: begin_ (it.begin_), end_ (it.end_), current_ (it.current_), sl@0: it1_begin_ (it.it1_begin_), it1_end_ (it.it1_end_), it1_ (it.it1_), sl@0: it2_begin_ (it.it2_begin_), it2_end_ (it.it2_end_), it2_ (it.it2_) { sl@0: BOOST_UBLAS_CHECK (current_ == end_ || sl@0: (current_ == 0 && it1_ != it1_end_) || sl@0: (current_ == 1 && it2_ != it2_end_), internal_logic ()); sl@0: } sl@0: sl@0: // Arithmetic sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator2 &operator ++ () { sl@0: BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ()); sl@0: if (current_ == 0) { sl@0: BOOST_UBLAS_CHECK (it1_ != it1_end_, internal_logic ()); sl@0: ++ it1_; sl@0: if (it1_ == it1_end_ && end_ == 1) { sl@0: it2_ = it2_begin_; sl@0: current_ = 1; sl@0: } sl@0: } else /* if (current_ == 1) */ { sl@0: BOOST_UBLAS_CHECK (it2_ != it2_end_, internal_logic ()); sl@0: ++ it2_; sl@0: if (it2_ == it2_end_ && end_ == 0) { sl@0: it1_ = it1_begin_; sl@0: current_ = 0; sl@0: } sl@0: } sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator2 &operator -- () { sl@0: BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ()); sl@0: if (current_ == 0) { sl@0: if (it1_ == it1_begin_ && begin_ == 1) { sl@0: it2_ = it2_end_; sl@0: BOOST_UBLAS_CHECK (it2_ != it2_begin_, internal_logic ()); sl@0: -- it2_; sl@0: current_ = 1; sl@0: } else { sl@0: -- it1_; sl@0: } sl@0: } else /* if (current_ == 1) */ { sl@0: if (it2_ == it2_begin_ && begin_ == 0) { sl@0: it1_ = it1_end_; sl@0: BOOST_UBLAS_CHECK (it1_ != it1_begin_, internal_logic ()); sl@0: -- it1_; sl@0: current_ = 0; sl@0: } else { sl@0: -- it2_; sl@0: } sl@0: } sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator2 &operator += (difference_type n) { sl@0: BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ()); sl@0: if (current_ == 0) { sl@0: size_type d = (std::min) (n, it1_end_ - it1_); sl@0: it1_ += d; sl@0: n -= d; sl@0: if (n > 0 || (end_ == 1 && it1_ == it1_end_)) { sl@0: BOOST_UBLAS_CHECK (end_ == 1, external_logic ()); sl@0: d = (std::min) (n, it2_end_ - it2_begin_); sl@0: it2_ = it2_begin_ + d; sl@0: n -= d; sl@0: current_ = 1; sl@0: } sl@0: } else /* if (current_ == 1) */ { sl@0: size_type d = (std::min) (n, it2_end_ - it2_); sl@0: it2_ += d; sl@0: n -= d; sl@0: if (n > 0 || (end_ == 0 && it2_ == it2_end_)) { sl@0: BOOST_UBLAS_CHECK (end_ == 0, external_logic ()); sl@0: d = (std::min) (n, it1_end_ - it1_begin_); sl@0: it1_ = it1_begin_ + d; sl@0: n -= d; sl@0: current_ = 0; sl@0: } sl@0: } sl@0: BOOST_UBLAS_CHECK (n == 0, external_logic ()); sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator2 &operator -= (difference_type n) { sl@0: BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ()); sl@0: if (current_ == 0) { sl@0: size_type d = (std::min) (n, it1_ - it1_begin_); sl@0: it1_ -= d; sl@0: n -= d; sl@0: if (n > 0) { sl@0: BOOST_UBLAS_CHECK (end_ == 1, external_logic ()); sl@0: d = (std::min) (n, it2_end_ - it2_begin_); sl@0: it2_ = it2_end_ - d; sl@0: n -= d; sl@0: current_ = 1; sl@0: } sl@0: } else /* if (current_ == 1) */ { sl@0: size_type d = (std::min) (n, it2_ - it2_begin_); sl@0: it2_ -= d; sl@0: n -= d; sl@0: if (n > 0) { sl@0: BOOST_UBLAS_CHECK (end_ == 0, external_logic ()); sl@0: d = (std::min) (n, it1_end_ - it1_begin_); sl@0: it1_ = it1_end_ - d; sl@0: n -= d; sl@0: current_ = 0; sl@0: } sl@0: } sl@0: BOOST_UBLAS_CHECK (n == 0, external_logic ()); sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: difference_type operator - (const const_iterator2 &it) const { sl@0: BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); sl@0: BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ()); sl@0: BOOST_UBLAS_CHECK (it.current_ == 0 || it.current_ == 1, internal_logic ()); sl@0: BOOST_UBLAS_CHECK (/* begin_ == it.begin_ && */ end_ == it.end_, internal_logic ()); sl@0: if (current_ == 0 && it.current_ == 0) { sl@0: return it1_ - it.it1_; sl@0: } else if (current_ == 0 && it.current_ == 1) { sl@0: if (end_ == 1 && it.end_ == 1) { sl@0: return (it1_ - it.it1_end_) + (it.it2_begin_ - it.it2_); sl@0: } else /* if (end_ == 0 && it.end_ == 0) */ { sl@0: return (it1_ - it.it1_begin_) + (it.it2_end_ - it.it2_); sl@0: } sl@0: sl@0: } else if (current_ == 1 && it.current_ == 0) { sl@0: if (end_ == 1 && it.end_ == 1) { sl@0: return (it2_ - it.it2_begin_) + (it.it1_end_ - it.it1_); sl@0: } else /* if (end_ == 0 && it.end_ == 0) */ { sl@0: return (it2_ - it.it2_end_) + (it.it1_begin_ - it.it1_); sl@0: } sl@0: } sl@0: /* current_ == 1 && it.current_ == 1 */ { sl@0: return it2_ - it.it2_; sl@0: } sl@0: } sl@0: sl@0: // Dereference sl@0: BOOST_UBLAS_INLINE sl@0: const_reference operator * () const { sl@0: BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ()); sl@0: if (current_ == 0) { sl@0: BOOST_UBLAS_CHECK (it1_ != it1_end_, internal_logic ()); sl@0: return *it1_; sl@0: } else /* if (current_ == 1) */ { sl@0: BOOST_UBLAS_CHECK (it2_ != it2_end_, internal_logic ()); sl@0: return *it2_; sl@0: } sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_reference operator [] (difference_type n) const { sl@0: return *(*this + n); sl@0: } sl@0: sl@0: #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: const_iterator1 begin () const { sl@0: return (*this) ().find1 (1, 0, index2 ()); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: const_iterator1 end () const { sl@0: return (*this) ().find1 (1, (*this) ().size1 (), index2 ()); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: const_reverse_iterator1 rbegin () const { sl@0: return const_reverse_iterator1 (end ()); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: const_reverse_iterator1 rend () const { sl@0: return const_reverse_iterator1 (begin ()); sl@0: } sl@0: #endif sl@0: sl@0: // Indices sl@0: BOOST_UBLAS_INLINE sl@0: size_type index1 () const { sl@0: BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ()); sl@0: if (current_ == 0) { sl@0: BOOST_UBLAS_CHECK (it1_ != it1_end_, internal_logic ()); sl@0: return it1_.index2 (); sl@0: } else /* if (current_ == 1) */ { sl@0: BOOST_UBLAS_CHECK (it2_ != it2_end_, internal_logic ()); sl@0: return it2_.index1 (); sl@0: } sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: size_type index2 () const { sl@0: BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ()); sl@0: if (current_ == 0) { sl@0: BOOST_UBLAS_CHECK (it1_ != it1_end_, internal_logic ()); sl@0: return it1_.index1 (); sl@0: } else /* if (current_ == 1) */ { sl@0: BOOST_UBLAS_CHECK (it2_ != it2_end_, internal_logic ()); sl@0: return it2_.index2 (); sl@0: } sl@0: } sl@0: sl@0: // Assignment sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator2 &operator = (const const_iterator2 &it) { sl@0: container_const_reference::assign (&it ()); sl@0: begin_ = it.begin_; sl@0: end_ = it.end_; sl@0: current_ = it.current_; sl@0: it1_begin_ = it.it1_begin_; sl@0: it1_end_ = it.it1_end_; sl@0: it1_ = it.it1_; sl@0: it2_begin_ = it.it2_begin_; sl@0: it2_end_ = it.it2_end_; sl@0: it2_ = it.it2_; sl@0: return *this; sl@0: } sl@0: sl@0: // Comparison sl@0: BOOST_UBLAS_INLINE sl@0: bool operator == (const const_iterator2 &it) const { sl@0: BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); sl@0: BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ()); sl@0: BOOST_UBLAS_CHECK (it.current_ == 0 || it.current_ == 1, internal_logic ()); sl@0: BOOST_UBLAS_CHECK (/* begin_ == it.begin_ && */ end_ == it.end_, internal_logic ()); sl@0: return (current_ == 0 && it.current_ == 0 && it1_ == it.it1_) || sl@0: (current_ == 1 && it.current_ == 1 && it2_ == it.it2_); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: bool operator < (const const_iterator2 &it) const { sl@0: BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); sl@0: return it - *this > 0; sl@0: } sl@0: sl@0: private: sl@0: int begin_; sl@0: int end_; sl@0: int current_; sl@0: const_subiterator1_type it1_begin_; sl@0: const_subiterator1_type it1_end_; sl@0: const_subiterator1_type it1_; sl@0: const_subiterator2_type it2_begin_; sl@0: const_subiterator2_type it2_end_; sl@0: const_subiterator2_type it2_; sl@0: }; sl@0: #endif sl@0: sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator2 begin2 () const { sl@0: return find2 (0, 0, 0); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_iterator2 end2 () const { sl@0: return find2 (0, 0, size2 ()); sl@0: } sl@0: sl@0: #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR sl@0: class iterator2: sl@0: public container_reference, sl@0: public random_access_iterator_base::iterator_category, sl@0: iterator2, value_type> { sl@0: public: sl@0: typedef typename subiterator2_type::value_type value_type; sl@0: typedef typename subiterator2_type::difference_type difference_type; sl@0: typedef typename subiterator2_type::reference reference; sl@0: typedef typename subiterator2_type::pointer pointer; sl@0: sl@0: typedef iterator1 dual_iterator_type; sl@0: typedef reverse_iterator1 dual_reverse_iterator_type; sl@0: sl@0: // Construction and destruction sl@0: BOOST_UBLAS_INLINE sl@0: iterator2 (): sl@0: container_reference (), it2_ () {} sl@0: BOOST_UBLAS_INLINE sl@0: iterator2 (self_type &m, const subiterator2_type &it2): sl@0: container_reference (m), it2_ (it2) {} sl@0: sl@0: // Arithmetic sl@0: BOOST_UBLAS_INLINE sl@0: iterator2 &operator ++ () { sl@0: ++ it2_; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: iterator2 &operator -- () { sl@0: -- it2_; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: iterator2 &operator += (difference_type n) { sl@0: it2_ += n; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: iterator2 &operator -= (difference_type n) { sl@0: it2_ -= n; sl@0: return *this; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: difference_type operator - (const iterator2 &it) const { sl@0: BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); sl@0: return it2_ - it.it2_; sl@0: } sl@0: sl@0: // Dereference sl@0: BOOST_UBLAS_INLINE sl@0: reference operator * () const { sl@0: return *it2_; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: reference operator [] (difference_type n) const { sl@0: return *(*this + n); sl@0: } sl@0: sl@0: #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: iterator1 begin () const { sl@0: return (*this) ().find1 (1, 0, index2 ()); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: iterator1 end () const { sl@0: return (*this) ().find1 (1, (*this) ().size1 (), index2 ()); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: reverse_iterator1 rbegin () const { sl@0: return reverse_iterator1 (end ()); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION sl@0: typename self_type:: sl@0: #endif sl@0: reverse_iterator1 rend () const { sl@0: return reverse_iterator1 (begin ()); sl@0: } sl@0: #endif sl@0: sl@0: // Indices sl@0: BOOST_UBLAS_INLINE sl@0: size_type index1 () const { sl@0: return it2_.index1 (); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: size_type index2 () const { sl@0: return it2_.index2 (); sl@0: } sl@0: sl@0: // Assignment sl@0: BOOST_UBLAS_INLINE sl@0: iterator2 &operator = (const iterator2 &it) { sl@0: container_reference::assign (&it ()); sl@0: it2_ = it.it2_; sl@0: return *this; sl@0: } sl@0: sl@0: // Comparison sl@0: BOOST_UBLAS_INLINE sl@0: bool operator == (const iterator2 &it) const { sl@0: BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); sl@0: return it2_ == it.it2_; sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: bool operator < (const iterator2 &it) const { sl@0: BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ()); sl@0: return it2_ < it.it2_; sl@0: } sl@0: sl@0: private: sl@0: subiterator2_type it2_; sl@0: sl@0: friend class const_iterator2; sl@0: }; sl@0: #endif sl@0: sl@0: BOOST_UBLAS_INLINE sl@0: iterator2 begin2 () { sl@0: return find2 (0, 0, 0); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: iterator2 end2 () { sl@0: return find2 (0, 0, size2 ()); sl@0: } sl@0: sl@0: // Reverse iterators sl@0: sl@0: BOOST_UBLAS_INLINE sl@0: const_reverse_iterator1 rbegin1 () const { sl@0: return const_reverse_iterator1 (end1 ()); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_reverse_iterator1 rend1 () const { sl@0: return const_reverse_iterator1 (begin1 ()); sl@0: } sl@0: sl@0: BOOST_UBLAS_INLINE sl@0: reverse_iterator1 rbegin1 () { sl@0: return reverse_iterator1 (end1 ()); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: reverse_iterator1 rend1 () { sl@0: return reverse_iterator1 (begin1 ()); sl@0: } sl@0: sl@0: BOOST_UBLAS_INLINE sl@0: const_reverse_iterator2 rbegin2 () const { sl@0: return const_reverse_iterator2 (end2 ()); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: const_reverse_iterator2 rend2 () const { sl@0: return const_reverse_iterator2 (begin2 ()); sl@0: } sl@0: sl@0: BOOST_UBLAS_INLINE sl@0: reverse_iterator2 rbegin2 () { sl@0: return reverse_iterator2 (end2 ()); sl@0: } sl@0: BOOST_UBLAS_INLINE sl@0: reverse_iterator2 rend2 () { sl@0: return reverse_iterator2 (begin2 ()); sl@0: } sl@0: sl@0: private: sl@0: matrix_closure_type data_; sl@0: }; sl@0: sl@0: // Specialization for temporary_traits sl@0: template sl@0: struct vector_temporary_traits< symmetric_adaptor > sl@0: : vector_temporary_traits< M > {} ; sl@0: template sl@0: struct vector_temporary_traits< const symmetric_adaptor > sl@0: : vector_temporary_traits< M > {} ; sl@0: sl@0: template sl@0: struct matrix_temporary_traits< symmetric_adaptor > sl@0: : matrix_temporary_traits< M > {} ; sl@0: template sl@0: struct matrix_temporary_traits< const symmetric_adaptor > sl@0: : matrix_temporary_traits< M > {} ; sl@0: sl@0: }}} sl@0: sl@0: #endif