os/ossrv/ossrv_pub/boost_apis/boost/numeric/ublas/symmetric.hpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
//
sl@0
     2
//  Copyright (c) 2000-2002
sl@0
     3
//  Joerg Walter, Mathias Koch
sl@0
     4
//
sl@0
     5
//  Permission to use, copy, modify, distribute and sell this software
sl@0
     6
//  and its documentation for any purpose is hereby granted without fee,
sl@0
     7
//  provided that the above copyright notice appear in all copies and
sl@0
     8
//  that both that copyright notice and this permission notice appear
sl@0
     9
//  in supporting documentation.  The authors make no representations
sl@0
    10
//  about the suitability of this software for any purpose.
sl@0
    11
//  It is provided "as is" without express or implied warranty.
sl@0
    12
//
sl@0
    13
//  The authors gratefully acknowledge the support of
sl@0
    14
//  GeNeSys mbH & Co. KG in producing this work.
sl@0
    15
//
sl@0
    16
sl@0
    17
#ifndef _BOOST_UBLAS_SYMMETRIC_
sl@0
    18
#define _BOOST_UBLAS_SYMMETRIC_
sl@0
    19
sl@0
    20
#include <boost/numeric/ublas/matrix.hpp>
sl@0
    21
#include <boost/numeric/ublas/detail/temporary.hpp>
sl@0
    22
sl@0
    23
// Iterators based on ideas of Jeremy Siek
sl@0
    24
// Symmetric matrices are square. Thanks to Peter Schmitteckert for spotting this.
sl@0
    25
sl@0
    26
namespace boost { namespace numeric { namespace ublas {
sl@0
    27
sl@0
    28
    template<class M>
sl@0
    29
    bool is_symmetric (const M &m) {
sl@0
    30
        typedef typename M::size_type size_type;
sl@0
    31
sl@0
    32
        if (m.size1 () != m.size2 ())
sl@0
    33
            return false;
sl@0
    34
        size_type size = BOOST_UBLAS_SAME (m.size1 (), m.size2 ());
sl@0
    35
        for (size_type i = 0; i < size; ++ i) {
sl@0
    36
            for (size_type j = i; j < size; ++ j) {
sl@0
    37
                if (m (i, j) != m (j, i))
sl@0
    38
                    return false;
sl@0
    39
            }
sl@0
    40
        }
sl@0
    41
        return true;
sl@0
    42
    }
sl@0
    43
sl@0
    44
    // Array based symmetric matrix class
sl@0
    45
    template<class T, class TRI, class L, class A>
sl@0
    46
    class symmetric_matrix:
sl@0
    47
        public matrix_container<symmetric_matrix<T, TRI, L, A> > {
sl@0
    48
sl@0
    49
        typedef T *pointer;
sl@0
    50
        typedef TRI triangular_type;
sl@0
    51
        typedef L layout_type;
sl@0
    52
        typedef symmetric_matrix<T, TRI, L, A> self_type;
sl@0
    53
    public:
sl@0
    54
#ifdef BOOST_UBLAS_ENABLE_PROXY_SHORTCUTS
sl@0
    55
        using matrix_container<self_type>::operator ();
sl@0
    56
#endif
sl@0
    57
        typedef typename A::size_type size_type;
sl@0
    58
        typedef typename A::difference_type difference_type;
sl@0
    59
        typedef T value_type;
sl@0
    60
        typedef const T &const_reference;
sl@0
    61
        typedef T &reference;
sl@0
    62
        typedef A array_type;
sl@0
    63
sl@0
    64
        typedef const matrix_reference<const self_type> const_closure_type;
sl@0
    65
        typedef matrix_reference<self_type> closure_type;
sl@0
    66
        typedef vector<T, A> vector_temporary_type;
sl@0
    67
        typedef matrix<T, L, A> matrix_temporary_type;  // general sub-matrix
sl@0
    68
        typedef packed_tag storage_category;
sl@0
    69
        typedef typename L::orientation_category orientation_category;
sl@0
    70
sl@0
    71
        // Construction and destruction
sl@0
    72
        BOOST_UBLAS_INLINE
sl@0
    73
        symmetric_matrix ():
sl@0
    74
            matrix_container<self_type> (),
sl@0
    75
            size_ (0), data_ (0) {}
sl@0
    76
        BOOST_UBLAS_INLINE
sl@0
    77
        symmetric_matrix (size_type size):
sl@0
    78
            matrix_container<self_type> (),
sl@0
    79
            size_ (BOOST_UBLAS_SAME (size, size)), data_ (triangular_type::packed_size (layout_type (), size, size)) {
sl@0
    80
        }
sl@0
    81
        BOOST_UBLAS_INLINE
sl@0
    82
        symmetric_matrix (size_type size1, size_type size2):
sl@0
    83
            matrix_container<self_type> (),
sl@0
    84
            size_ (BOOST_UBLAS_SAME (size1, size2)), data_ (triangular_type::packed_size (layout_type (), size1, size2)) {
sl@0
    85
        }
sl@0
    86
        BOOST_UBLAS_INLINE
sl@0
    87
        symmetric_matrix (size_type size, const array_type &data):
sl@0
    88
            matrix_container<self_type> (),
sl@0
    89
            size_ (size), data_ (data) {}
sl@0
    90
        BOOST_UBLAS_INLINE
sl@0
    91
        symmetric_matrix (const symmetric_matrix &m):
sl@0
    92
            matrix_container<self_type> (),
sl@0
    93
            size_ (m.size_), data_ (m.data_) {}
sl@0
    94
        template<class AE>
sl@0
    95
        BOOST_UBLAS_INLINE
sl@0
    96
        symmetric_matrix (const matrix_expression<AE> &ae):
sl@0
    97
            matrix_container<self_type> (),
sl@0
    98
            size_ (BOOST_UBLAS_SAME (ae ().size1 (), ae ().size2 ())),
sl@0
    99
            data_ (triangular_type::packed_size (layout_type (), size_, size_)) {
sl@0
   100
            matrix_assign<scalar_assign> (*this, ae);
sl@0
   101
        }
sl@0
   102
sl@0
   103
        // Accessors
sl@0
   104
        BOOST_UBLAS_INLINE
sl@0
   105
        size_type size1 () const {
sl@0
   106
            return size_;
sl@0
   107
        }
sl@0
   108
        BOOST_UBLAS_INLINE
sl@0
   109
        size_type size2 () const {
sl@0
   110
            return size_;
sl@0
   111
        }
sl@0
   112
sl@0
   113
        // Storage accessors
sl@0
   114
        BOOST_UBLAS_INLINE
sl@0
   115
        const array_type &data () const {
sl@0
   116
            return data_;
sl@0
   117
        }
sl@0
   118
        BOOST_UBLAS_INLINE
sl@0
   119
        array_type &data () {
sl@0
   120
            return data_;
sl@0
   121
        }
sl@0
   122
sl@0
   123
        // Resizing
sl@0
   124
        BOOST_UBLAS_INLINE
sl@0
   125
        void resize (size_type size, bool preserve = true) {
sl@0
   126
            if (preserve) {
sl@0
   127
                self_type temporary (size, size);
sl@0
   128
                detail::matrix_resize_preserve<layout_type> (*this, temporary);
sl@0
   129
            }
sl@0
   130
            else {
sl@0
   131
                data ().resize (triangular_type::packed_size (layout_type (), size, size));
sl@0
   132
                size_ = size;
sl@0
   133
            }
sl@0
   134
        }
sl@0
   135
        BOOST_UBLAS_INLINE
sl@0
   136
        void resize (size_type size1, size_type size2, bool preserve = true) {
sl@0
   137
            resize (BOOST_UBLAS_SAME (size1, size2), preserve);
sl@0
   138
        }
sl@0
   139
        BOOST_UBLAS_INLINE
sl@0
   140
        void resize_packed_preserve (size_type size) {
sl@0
   141
            size_ = BOOST_UBLAS_SAME (size, size);
sl@0
   142
            data ().resize (triangular_type::packed_size (layout_type (), size_, size_), value_type ());
sl@0
   143
        }
sl@0
   144
sl@0
   145
        // Element access
sl@0
   146
        BOOST_UBLAS_INLINE
sl@0
   147
        const_reference operator () (size_type i, size_type j) const {
sl@0
   148
            BOOST_UBLAS_CHECK (i < size_, bad_index ());
sl@0
   149
            BOOST_UBLAS_CHECK (j < size_, bad_index ());
sl@0
   150
            if (triangular_type::other (i, j))
sl@0
   151
                return data () [triangular_type::element (layout_type (), i, size_, j, size_)];
sl@0
   152
            else
sl@0
   153
                return data () [triangular_type::element (layout_type (), j, size_, i, size_)];
sl@0
   154
        }
sl@0
   155
        BOOST_UBLAS_INLINE
sl@0
   156
        reference at_element (size_type i, size_type j) {
sl@0
   157
            BOOST_UBLAS_CHECK (i < size_, bad_index ());
sl@0
   158
            BOOST_UBLAS_CHECK (j < size_, bad_index ());
sl@0
   159
            return data () [triangular_type::element (layout_type (), i, size_, j, size_)];
sl@0
   160
        }
sl@0
   161
        BOOST_UBLAS_INLINE
sl@0
   162
        reference operator () (size_type i, size_type j) {
sl@0
   163
            BOOST_UBLAS_CHECK (i < size_, bad_index ());
sl@0
   164
            BOOST_UBLAS_CHECK (j < size_, bad_index ());
sl@0
   165
            if (triangular_type::other (i, j))
sl@0
   166
                return data () [triangular_type::element (layout_type (), i, size_, j, size_)];
sl@0
   167
            else
sl@0
   168
                return data () [triangular_type::element (layout_type (), j, size_, i, size_)];
sl@0
   169
        }
sl@0
   170
sl@0
   171
        // Element assignment
sl@0
   172
        BOOST_UBLAS_INLINE
sl@0
   173
        reference insert_element (size_type i, size_type j, const_reference t) {
sl@0
   174
            return (operator () (i, j) = t);
sl@0
   175
        }
sl@0
   176
        BOOST_UBLAS_INLINE
sl@0
   177
        void erase_element (size_type i, size_type j) {
sl@0
   178
            operator () (i, j) = value_type/*zero*/();
sl@0
   179
        }
sl@0
   180
        
sl@0
   181
        // Zeroing
sl@0
   182
        BOOST_UBLAS_INLINE
sl@0
   183
        void clear () {
sl@0
   184
            // data ().clear ();
sl@0
   185
            std::fill (data ().begin (), data ().end (), value_type/*zero*/());
sl@0
   186
        }
sl@0
   187
sl@0
   188
        // Assignment
sl@0
   189
        BOOST_UBLAS_INLINE
sl@0
   190
        symmetric_matrix &operator = (const symmetric_matrix &m) {
sl@0
   191
            size_ = m.size_;
sl@0
   192
            data () = m.data ();
sl@0
   193
            return *this;
sl@0
   194
        }
sl@0
   195
        BOOST_UBLAS_INLINE
sl@0
   196
        symmetric_matrix &assign_temporary (symmetric_matrix &m) {
sl@0
   197
            swap (m);
sl@0
   198
            return *this;
sl@0
   199
        }
sl@0
   200
        template<class AE>
sl@0
   201
        BOOST_UBLAS_INLINE
sl@0
   202
        symmetric_matrix &operator = (const matrix_expression<AE> &ae) {
sl@0
   203
            self_type temporary (ae);
sl@0
   204
            return assign_temporary (temporary);
sl@0
   205
        }
sl@0
   206
        template<class AE>
sl@0
   207
        BOOST_UBLAS_INLINE
sl@0
   208
        symmetric_matrix &assign (const matrix_expression<AE> &ae) {
sl@0
   209
            matrix_assign<scalar_assign> (*this, ae);
sl@0
   210
            return *this;
sl@0
   211
        }
sl@0
   212
        template<class AE>
sl@0
   213
        BOOST_UBLAS_INLINE
sl@0
   214
        symmetric_matrix& operator += (const matrix_expression<AE> &ae) {
sl@0
   215
            self_type temporary (*this + ae);
sl@0
   216
            return assign_temporary (temporary);
sl@0
   217
        }
sl@0
   218
        template<class AE>
sl@0
   219
        BOOST_UBLAS_INLINE
sl@0
   220
        symmetric_matrix &plus_assign (const matrix_expression<AE> &ae) {
sl@0
   221
            matrix_assign<scalar_plus_assign> (*this, ae);
sl@0
   222
            return *this;
sl@0
   223
        }
sl@0
   224
        template<class AE>
sl@0
   225
        BOOST_UBLAS_INLINE
sl@0
   226
        symmetric_matrix& operator -= (const matrix_expression<AE> &ae) {
sl@0
   227
            self_type temporary (*this - ae);
sl@0
   228
            return assign_temporary (temporary);
sl@0
   229
        }
sl@0
   230
        template<class AE>
sl@0
   231
        BOOST_UBLAS_INLINE
sl@0
   232
        symmetric_matrix &minus_assign (const matrix_expression<AE> &ae) {
sl@0
   233
            matrix_assign<scalar_minus_assign> (*this, ae);
sl@0
   234
            return *this;
sl@0
   235
        }
sl@0
   236
        template<class AT>
sl@0
   237
        BOOST_UBLAS_INLINE
sl@0
   238
        symmetric_matrix& operator *= (const AT &at) {
sl@0
   239
            matrix_assign_scalar<scalar_multiplies_assign> (*this, at);
sl@0
   240
            return *this;
sl@0
   241
        }
sl@0
   242
        template<class AT>
sl@0
   243
        BOOST_UBLAS_INLINE
sl@0
   244
        symmetric_matrix& operator /= (const AT &at) {
sl@0
   245
            matrix_assign_scalar<scalar_divides_assign> (*this, at);
sl@0
   246
            return *this;
sl@0
   247
        }
sl@0
   248
sl@0
   249
        // Swapping
sl@0
   250
        BOOST_UBLAS_INLINE
sl@0
   251
        void swap (symmetric_matrix &m) {
sl@0
   252
            if (this != &m) {
sl@0
   253
                std::swap (size_, m.size_);
sl@0
   254
                data ().swap (m.data ());
sl@0
   255
            }
sl@0
   256
        }
sl@0
   257
        BOOST_UBLAS_INLINE
sl@0
   258
        friend void swap (symmetric_matrix &m1, symmetric_matrix &m2) {
sl@0
   259
            m1.swap (m2);
sl@0
   260
        }
sl@0
   261
sl@0
   262
        // Iterator types
sl@0
   263
#ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR
sl@0
   264
        typedef indexed_iterator1<self_type, packed_random_access_iterator_tag> iterator1;
sl@0
   265
        typedef indexed_iterator2<self_type, packed_random_access_iterator_tag> iterator2;
sl@0
   266
        typedef indexed_const_iterator1<self_type, dense_random_access_iterator_tag> const_iterator1;
sl@0
   267
        typedef indexed_const_iterator2<self_type, dense_random_access_iterator_tag> const_iterator2;
sl@0
   268
#else
sl@0
   269
        class const_iterator1;
sl@0
   270
        class iterator1;
sl@0
   271
        class const_iterator2;
sl@0
   272
        class iterator2;
sl@0
   273
#endif
sl@0
   274
        typedef reverse_iterator_base1<const_iterator1> const_reverse_iterator1;
sl@0
   275
        typedef reverse_iterator_base1<iterator1> reverse_iterator1;
sl@0
   276
        typedef reverse_iterator_base2<const_iterator2> const_reverse_iterator2;
sl@0
   277
        typedef reverse_iterator_base2<iterator2> reverse_iterator2;
sl@0
   278
sl@0
   279
        // Element lookup
sl@0
   280
        BOOST_UBLAS_INLINE
sl@0
   281
        const_iterator1 find1 (int /* rank */, size_type i, size_type j) const {
sl@0
   282
            return const_iterator1 (*this, i, j);
sl@0
   283
        }
sl@0
   284
        BOOST_UBLAS_INLINE
sl@0
   285
        iterator1 find1 (int rank, size_type i, size_type j) {
sl@0
   286
            if (rank == 1)
sl@0
   287
                i = triangular_type::mutable_restrict1 (i, j);
sl@0
   288
            return iterator1 (*this, i, j);
sl@0
   289
        }
sl@0
   290
        BOOST_UBLAS_INLINE
sl@0
   291
        const_iterator2 find2 (int /* rank */, size_type i, size_type j) const {
sl@0
   292
            return const_iterator2 (*this, i, j);
sl@0
   293
        }
sl@0
   294
        BOOST_UBLAS_INLINE
sl@0
   295
        iterator2 find2 (int rank, size_type i, size_type j) {
sl@0
   296
            if (rank == 1)
sl@0
   297
                j = triangular_type::mutable_restrict2 (i, j);
sl@0
   298
            return iterator2 (*this, i, j);
sl@0
   299
        }
sl@0
   300
sl@0
   301
        // Iterators simply are indices.
sl@0
   302
sl@0
   303
#ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
sl@0
   304
        class const_iterator1:
sl@0
   305
            public container_const_reference<symmetric_matrix>,
sl@0
   306
            public random_access_iterator_base<dense_random_access_iterator_tag,
sl@0
   307
                                               const_iterator1, value_type> {
sl@0
   308
        public:
sl@0
   309
            typedef typename symmetric_matrix::value_type value_type;
sl@0
   310
            typedef typename symmetric_matrix::difference_type difference_type;
sl@0
   311
            typedef typename symmetric_matrix::const_reference reference;
sl@0
   312
            typedef const typename symmetric_matrix::pointer pointer;
sl@0
   313
sl@0
   314
            typedef const_iterator2 dual_iterator_type;
sl@0
   315
            typedef const_reverse_iterator2 dual_reverse_iterator_type;
sl@0
   316
sl@0
   317
            // Construction and destruction
sl@0
   318
            BOOST_UBLAS_INLINE
sl@0
   319
            const_iterator1 ():
sl@0
   320
                container_const_reference<self_type> (), it1_ (), it2_ () {}
sl@0
   321
            BOOST_UBLAS_INLINE
sl@0
   322
            const_iterator1 (const self_type &m, size_type it1, size_type it2):
sl@0
   323
                container_const_reference<self_type> (m), it1_ (it1), it2_ (it2) {}
sl@0
   324
            BOOST_UBLAS_INLINE
sl@0
   325
            const_iterator1 (const iterator1 &it):
sl@0
   326
                container_const_reference<self_type> (it ()), it1_ (it.it1_), it2_ (it.it2_) {}
sl@0
   327
sl@0
   328
            // Arithmetic
sl@0
   329
            BOOST_UBLAS_INLINE
sl@0
   330
            const_iterator1 &operator ++ () {
sl@0
   331
                ++ it1_;
sl@0
   332
                return *this;
sl@0
   333
            }
sl@0
   334
            BOOST_UBLAS_INLINE
sl@0
   335
            const_iterator1 &operator -- () {
sl@0
   336
                -- it1_;
sl@0
   337
                return *this;
sl@0
   338
            }
sl@0
   339
            BOOST_UBLAS_INLINE
sl@0
   340
            const_iterator1 &operator += (difference_type n) {
sl@0
   341
                it1_ += n;
sl@0
   342
                return *this;
sl@0
   343
            }
sl@0
   344
            BOOST_UBLAS_INLINE
sl@0
   345
            const_iterator1 &operator -= (difference_type n) {
sl@0
   346
                it1_ -= n;
sl@0
   347
                return *this;
sl@0
   348
            }
sl@0
   349
            BOOST_UBLAS_INLINE
sl@0
   350
            difference_type operator - (const const_iterator1 &it) const {
sl@0
   351
                BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
sl@0
   352
                BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ());
sl@0
   353
                return it1_ - it.it1_;
sl@0
   354
            }
sl@0
   355
sl@0
   356
            // Dereference
sl@0
   357
            BOOST_UBLAS_INLINE
sl@0
   358
            const_reference operator * () const {
sl@0
   359
                return (*this) () (it1_, it2_);
sl@0
   360
            }
sl@0
   361
            BOOST_UBLAS_INLINE
sl@0
   362
            const_reference operator [] (difference_type n) const {
sl@0
   363
                return *(*this + n);
sl@0
   364
            }
sl@0
   365
sl@0
   366
#ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
sl@0
   367
            BOOST_UBLAS_INLINE
sl@0
   368
#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
sl@0
   369
            typename self_type::
sl@0
   370
#endif
sl@0
   371
            const_iterator2 begin () const {
sl@0
   372
                return (*this) ().find2 (1, it1_, 0);
sl@0
   373
            }
sl@0
   374
            BOOST_UBLAS_INLINE
sl@0
   375
#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
sl@0
   376
            typename self_type::
sl@0
   377
#endif
sl@0
   378
            const_iterator2 end () const {
sl@0
   379
                return (*this) ().find2 (1, it1_, (*this) ().size2 ());
sl@0
   380
            }
sl@0
   381
            BOOST_UBLAS_INLINE
sl@0
   382
#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
sl@0
   383
            typename self_type::
sl@0
   384
#endif
sl@0
   385
            const_reverse_iterator2 rbegin () const {
sl@0
   386
                return const_reverse_iterator2 (end ());
sl@0
   387
            }
sl@0
   388
            BOOST_UBLAS_INLINE
sl@0
   389
#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
sl@0
   390
            typename self_type::
sl@0
   391
#endif
sl@0
   392
            const_reverse_iterator2 rend () const {
sl@0
   393
                return const_reverse_iterator2 (begin ());
sl@0
   394
            }
sl@0
   395
#endif
sl@0
   396
sl@0
   397
            // Indices
sl@0
   398
            BOOST_UBLAS_INLINE
sl@0
   399
            size_type index1 () const {
sl@0
   400
                return it1_;
sl@0
   401
            }
sl@0
   402
            BOOST_UBLAS_INLINE
sl@0
   403
            size_type index2 () const {
sl@0
   404
                return it2_;
sl@0
   405
            }
sl@0
   406
sl@0
   407
            // Assignment
sl@0
   408
            BOOST_UBLAS_INLINE
sl@0
   409
            const_iterator1 &operator = (const const_iterator1 &it) {
sl@0
   410
                container_const_reference<self_type>::assign (&it ());
sl@0
   411
                it1_ = it.it1_;
sl@0
   412
                it2_ = it.it2_;
sl@0
   413
                return *this;
sl@0
   414
            }
sl@0
   415
sl@0
   416
            // Comparison
sl@0
   417
            BOOST_UBLAS_INLINE
sl@0
   418
            bool operator == (const const_iterator1 &it) const {
sl@0
   419
                BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
sl@0
   420
                BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ());
sl@0
   421
                return it1_ == it.it1_;
sl@0
   422
            }
sl@0
   423
            BOOST_UBLAS_INLINE
sl@0
   424
            bool operator < (const const_iterator1 &it) const {
sl@0
   425
                BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
sl@0
   426
                BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ());
sl@0
   427
                return it1_ < it.it1_;
sl@0
   428
            }
sl@0
   429
sl@0
   430
        private:
sl@0
   431
            size_type it1_;
sl@0
   432
            size_type it2_;
sl@0
   433
        };
sl@0
   434
#endif
sl@0
   435
sl@0
   436
        BOOST_UBLAS_INLINE
sl@0
   437
        const_iterator1 begin1 () const {
sl@0
   438
            return find1 (0, 0, 0);
sl@0
   439
        }
sl@0
   440
        BOOST_UBLAS_INLINE
sl@0
   441
        const_iterator1 end1 () const {
sl@0
   442
            return find1 (0, size_, 0);
sl@0
   443
        }
sl@0
   444
sl@0
   445
#ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
sl@0
   446
        class iterator1:
sl@0
   447
            public container_reference<symmetric_matrix>,
sl@0
   448
            public random_access_iterator_base<packed_random_access_iterator_tag,
sl@0
   449
                                               iterator1, value_type> {
sl@0
   450
        public:
sl@0
   451
            typedef typename symmetric_matrix::value_type value_type;
sl@0
   452
            typedef typename symmetric_matrix::difference_type difference_type;
sl@0
   453
            typedef typename symmetric_matrix::reference reference;
sl@0
   454
            typedef typename symmetric_matrix::pointer pointer;
sl@0
   455
            typedef iterator2 dual_iterator_type;
sl@0
   456
            typedef reverse_iterator2 dual_reverse_iterator_type;
sl@0
   457
sl@0
   458
            // Construction and destruction
sl@0
   459
            BOOST_UBLAS_INLINE
sl@0
   460
            iterator1 ():
sl@0
   461
                container_reference<self_type> (), it1_ (), it2_ () {}
sl@0
   462
            BOOST_UBLAS_INLINE
sl@0
   463
            iterator1 (self_type &m, size_type it1, size_type it2):
sl@0
   464
                container_reference<self_type> (m), it1_ (it1), it2_ (it2) {}
sl@0
   465
sl@0
   466
            // Arithmetic
sl@0
   467
            BOOST_UBLAS_INLINE
sl@0
   468
            iterator1 &operator ++ () {
sl@0
   469
                ++ it1_;
sl@0
   470
                return *this;
sl@0
   471
            }
sl@0
   472
            BOOST_UBLAS_INLINE
sl@0
   473
            iterator1 &operator -- () {
sl@0
   474
                -- it1_;
sl@0
   475
                return *this;
sl@0
   476
            }
sl@0
   477
            BOOST_UBLAS_INLINE
sl@0
   478
            iterator1 &operator += (difference_type n) {
sl@0
   479
                it1_ += n;
sl@0
   480
                return *this;
sl@0
   481
            }
sl@0
   482
            BOOST_UBLAS_INLINE
sl@0
   483
            iterator1 &operator -= (difference_type n) {
sl@0
   484
                it1_ -= n;
sl@0
   485
                return *this;
sl@0
   486
            }
sl@0
   487
            BOOST_UBLAS_INLINE
sl@0
   488
            difference_type operator - (const iterator1 &it) const {
sl@0
   489
                BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
sl@0
   490
                BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ());
sl@0
   491
                return it1_ - it.it1_;
sl@0
   492
            }
sl@0
   493
sl@0
   494
            // Dereference
sl@0
   495
            BOOST_UBLAS_INLINE
sl@0
   496
            reference operator * () const {
sl@0
   497
                return (*this) () (it1_, it2_);
sl@0
   498
            }
sl@0
   499
            BOOST_UBLAS_INLINE
sl@0
   500
            reference operator [] (difference_type n) const {
sl@0
   501
                return *(*this + n);
sl@0
   502
            }
sl@0
   503
sl@0
   504
#ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
sl@0
   505
            BOOST_UBLAS_INLINE
sl@0
   506
#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
sl@0
   507
            typename self_type::
sl@0
   508
#endif
sl@0
   509
            iterator2 begin () const {
sl@0
   510
                return (*this) ().find2 (1, it1_, 0);
sl@0
   511
            }
sl@0
   512
            BOOST_UBLAS_INLINE
sl@0
   513
#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
sl@0
   514
            typename self_type::
sl@0
   515
#endif
sl@0
   516
            iterator2 end () const {
sl@0
   517
                return (*this) ().find2 (1, it1_, (*this) ().size2 ());
sl@0
   518
            }
sl@0
   519
            BOOST_UBLAS_INLINE
sl@0
   520
#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
sl@0
   521
            typename self_type::
sl@0
   522
#endif
sl@0
   523
            reverse_iterator2 rbegin () const {
sl@0
   524
                return reverse_iterator2 (end ());
sl@0
   525
            }
sl@0
   526
            BOOST_UBLAS_INLINE
sl@0
   527
#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
sl@0
   528
            typename self_type::
sl@0
   529
#endif
sl@0
   530
            reverse_iterator2 rend () const {
sl@0
   531
                return reverse_iterator2 (begin ());
sl@0
   532
            }
sl@0
   533
#endif
sl@0
   534
sl@0
   535
            // Indices
sl@0
   536
            BOOST_UBLAS_INLINE
sl@0
   537
            size_type index1 () const {
sl@0
   538
                return it1_;
sl@0
   539
            }
sl@0
   540
            BOOST_UBLAS_INLINE
sl@0
   541
            size_type index2 () const {
sl@0
   542
                return it2_;
sl@0
   543
            }
sl@0
   544
sl@0
   545
            // Assignment
sl@0
   546
            BOOST_UBLAS_INLINE
sl@0
   547
            iterator1 &operator = (const iterator1 &it) {
sl@0
   548
                container_reference<self_type>::assign (&it ());
sl@0
   549
                it1_ = it.it1_;
sl@0
   550
                it2_ = it.it2_;
sl@0
   551
                return *this;
sl@0
   552
            }
sl@0
   553
sl@0
   554
            // Comparison
sl@0
   555
            BOOST_UBLAS_INLINE
sl@0
   556
            bool operator == (const iterator1 &it) const {
sl@0
   557
                BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
sl@0
   558
                BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ());
sl@0
   559
                return it1_ == it.it1_;
sl@0
   560
            }
sl@0
   561
            BOOST_UBLAS_INLINE
sl@0
   562
            bool operator < (const iterator1 &it) const {
sl@0
   563
                BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
sl@0
   564
                BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ());
sl@0
   565
                return it1_ < it.it1_;
sl@0
   566
            }
sl@0
   567
sl@0
   568
        private:
sl@0
   569
            size_type it1_;
sl@0
   570
            size_type it2_;
sl@0
   571
sl@0
   572
            friend class const_iterator1;
sl@0
   573
        };
sl@0
   574
#endif
sl@0
   575
sl@0
   576
        BOOST_UBLAS_INLINE
sl@0
   577
        iterator1 begin1 () {
sl@0
   578
            return find1 (0, 0, 0);
sl@0
   579
        }
sl@0
   580
        BOOST_UBLAS_INLINE
sl@0
   581
        iterator1 end1 () {
sl@0
   582
            return find1 (0, size_, 0);
sl@0
   583
        }
sl@0
   584
sl@0
   585
#ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
sl@0
   586
        class const_iterator2:
sl@0
   587
            public container_const_reference<symmetric_matrix>,
sl@0
   588
            public random_access_iterator_base<dense_random_access_iterator_tag,
sl@0
   589
                                               const_iterator2, value_type> {
sl@0
   590
        public:
sl@0
   591
            typedef typename symmetric_matrix::value_type value_type;
sl@0
   592
            typedef typename symmetric_matrix::difference_type difference_type;
sl@0
   593
            typedef typename symmetric_matrix::const_reference reference;
sl@0
   594
            typedef const typename symmetric_matrix::pointer pointer;
sl@0
   595
sl@0
   596
            typedef const_iterator1 dual_iterator_type;
sl@0
   597
            typedef const_reverse_iterator1 dual_reverse_iterator_type;
sl@0
   598
sl@0
   599
            // Construction and destruction
sl@0
   600
            BOOST_UBLAS_INLINE
sl@0
   601
            const_iterator2 ():
sl@0
   602
                container_const_reference<self_type> (), it1_ (), it2_ () {}
sl@0
   603
            BOOST_UBLAS_INLINE
sl@0
   604
            const_iterator2 (const self_type &m, size_type it1, size_type it2):
sl@0
   605
                container_const_reference<self_type> (m), it1_ (it1), it2_ (it2) {}
sl@0
   606
            BOOST_UBLAS_INLINE
sl@0
   607
            const_iterator2 (const iterator2 &it):
sl@0
   608
                container_const_reference<self_type> (it ()), it1_ (it.it1_), it2_ (it.it2_) {}
sl@0
   609
sl@0
   610
            // Arithmetic
sl@0
   611
            BOOST_UBLAS_INLINE
sl@0
   612
            const_iterator2 &operator ++ () {
sl@0
   613
                ++ it2_;
sl@0
   614
                return *this;
sl@0
   615
            }
sl@0
   616
            BOOST_UBLAS_INLINE
sl@0
   617
            const_iterator2 &operator -- () {
sl@0
   618
                -- it2_;
sl@0
   619
                return *this;
sl@0
   620
            }
sl@0
   621
            BOOST_UBLAS_INLINE
sl@0
   622
            const_iterator2 &operator += (difference_type n) {
sl@0
   623
                it2_ += n;
sl@0
   624
                return *this;
sl@0
   625
            }
sl@0
   626
            BOOST_UBLAS_INLINE
sl@0
   627
            const_iterator2 &operator -= (difference_type n) {
sl@0
   628
                it2_ -= n;
sl@0
   629
                return *this;
sl@0
   630
            }
sl@0
   631
            BOOST_UBLAS_INLINE
sl@0
   632
            difference_type operator - (const const_iterator2 &it) const {
sl@0
   633
                BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
sl@0
   634
                BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ());
sl@0
   635
                return it2_ - it.it2_;
sl@0
   636
            }
sl@0
   637
sl@0
   638
            // Dereference
sl@0
   639
            BOOST_UBLAS_INLINE
sl@0
   640
            const_reference operator * () const {
sl@0
   641
                return (*this) () (it1_, it2_);
sl@0
   642
            }
sl@0
   643
            BOOST_UBLAS_INLINE
sl@0
   644
            const_reference operator [] (difference_type n) const {
sl@0
   645
                return *(*this + n);
sl@0
   646
            }
sl@0
   647
sl@0
   648
#ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
sl@0
   649
            BOOST_UBLAS_INLINE
sl@0
   650
#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
sl@0
   651
            typename self_type::
sl@0
   652
#endif
sl@0
   653
            const_iterator1 begin () const {
sl@0
   654
                return (*this) ().find1 (1, 0, it2_);
sl@0
   655
            }
sl@0
   656
            BOOST_UBLAS_INLINE
sl@0
   657
#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
sl@0
   658
            typename self_type::
sl@0
   659
#endif
sl@0
   660
            const_iterator1 end () const {
sl@0
   661
                return (*this) ().find1 (1, (*this) ().size1 (), it2_);
sl@0
   662
            }
sl@0
   663
            BOOST_UBLAS_INLINE
sl@0
   664
#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
sl@0
   665
            typename self_type::
sl@0
   666
#endif
sl@0
   667
            const_reverse_iterator1 rbegin () const {
sl@0
   668
                return const_reverse_iterator1 (end ());
sl@0
   669
            }
sl@0
   670
            BOOST_UBLAS_INLINE
sl@0
   671
#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
sl@0
   672
            typename self_type::
sl@0
   673
#endif
sl@0
   674
            const_reverse_iterator1 rend () const {
sl@0
   675
                return const_reverse_iterator1 (begin ());
sl@0
   676
            }
sl@0
   677
#endif
sl@0
   678
sl@0
   679
            // Indices
sl@0
   680
            BOOST_UBLAS_INLINE
sl@0
   681
            size_type index1 () const {
sl@0
   682
                return it1_;
sl@0
   683
            }
sl@0
   684
            BOOST_UBLAS_INLINE
sl@0
   685
            size_type index2 () const {
sl@0
   686
                return it2_;
sl@0
   687
            }
sl@0
   688
sl@0
   689
            // Assignment
sl@0
   690
            BOOST_UBLAS_INLINE
sl@0
   691
            const_iterator2 &operator = (const const_iterator2 &it) {
sl@0
   692
                container_const_reference<self_type>::assign (&it ());
sl@0
   693
                it1_ = it.it1_;
sl@0
   694
                it2_ = it.it2_;
sl@0
   695
                return *this;
sl@0
   696
            }
sl@0
   697
sl@0
   698
            // Comparison
sl@0
   699
            BOOST_UBLAS_INLINE
sl@0
   700
            bool operator == (const const_iterator2 &it) const {
sl@0
   701
                BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
sl@0
   702
                BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ());
sl@0
   703
                return it2_ == it.it2_;
sl@0
   704
            }
sl@0
   705
            BOOST_UBLAS_INLINE
sl@0
   706
            bool operator < (const const_iterator2 &it) const {
sl@0
   707
                BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
sl@0
   708
                BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ());
sl@0
   709
                return it2_ < it.it2_;
sl@0
   710
            }
sl@0
   711
sl@0
   712
        private:
sl@0
   713
            size_type it1_;
sl@0
   714
            size_type it2_;
sl@0
   715
        };
sl@0
   716
#endif
sl@0
   717
sl@0
   718
        BOOST_UBLAS_INLINE
sl@0
   719
        const_iterator2 begin2 () const {
sl@0
   720
            return find2 (0, 0, 0);
sl@0
   721
        }
sl@0
   722
        BOOST_UBLAS_INLINE
sl@0
   723
        const_iterator2 end2 () const {
sl@0
   724
            return find2 (0, 0, size_);
sl@0
   725
        }
sl@0
   726
sl@0
   727
#ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
sl@0
   728
        class iterator2:
sl@0
   729
            public container_reference<symmetric_matrix>,
sl@0
   730
            public random_access_iterator_base<packed_random_access_iterator_tag,
sl@0
   731
                                               iterator2, value_type> {
sl@0
   732
        public:
sl@0
   733
            typedef typename symmetric_matrix::value_type value_type;
sl@0
   734
            typedef typename symmetric_matrix::difference_type difference_type;
sl@0
   735
            typedef typename symmetric_matrix::reference reference;
sl@0
   736
            typedef typename symmetric_matrix::pointer pointer;
sl@0
   737
sl@0
   738
            typedef iterator1 dual_iterator_type;
sl@0
   739
            typedef reverse_iterator1 dual_reverse_iterator_type;
sl@0
   740
sl@0
   741
            // Construction and destruction
sl@0
   742
            BOOST_UBLAS_INLINE
sl@0
   743
            iterator2 ():
sl@0
   744
                container_reference<self_type> (), it1_ (), it2_ () {}
sl@0
   745
            BOOST_UBLAS_INLINE
sl@0
   746
            iterator2 (self_type &m, size_type it1, size_type it2):
sl@0
   747
                container_reference<self_type> (m), it1_ (it1), it2_ (it2) {}
sl@0
   748
sl@0
   749
            // Arithmetic
sl@0
   750
            BOOST_UBLAS_INLINE
sl@0
   751
            iterator2 &operator ++ () {
sl@0
   752
                ++ it2_;
sl@0
   753
                return *this;
sl@0
   754
            }
sl@0
   755
            BOOST_UBLAS_INLINE
sl@0
   756
            iterator2 &operator -- () {
sl@0
   757
                -- it2_;
sl@0
   758
                return *this;
sl@0
   759
            }
sl@0
   760
            BOOST_UBLAS_INLINE
sl@0
   761
            iterator2 &operator += (difference_type n) {
sl@0
   762
                it2_ += n;
sl@0
   763
                return *this;
sl@0
   764
            }
sl@0
   765
            BOOST_UBLAS_INLINE
sl@0
   766
            iterator2 &operator -= (difference_type n) {
sl@0
   767
                it2_ -= n;
sl@0
   768
                return *this;
sl@0
   769
            }
sl@0
   770
            BOOST_UBLAS_INLINE
sl@0
   771
            difference_type operator - (const iterator2 &it) const {
sl@0
   772
                BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
sl@0
   773
                BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ());
sl@0
   774
                return it2_ - it.it2_;
sl@0
   775
            }
sl@0
   776
sl@0
   777
            // Dereference
sl@0
   778
            BOOST_UBLAS_INLINE
sl@0
   779
            reference operator * () const {
sl@0
   780
                return (*this) () (it1_, it2_);
sl@0
   781
            }
sl@0
   782
            BOOST_UBLAS_INLINE
sl@0
   783
            reference operator [] (difference_type n) const {
sl@0
   784
                return *(*this + n);
sl@0
   785
            }
sl@0
   786
sl@0
   787
#ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
sl@0
   788
            BOOST_UBLAS_INLINE
sl@0
   789
#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
sl@0
   790
            typename self_type::
sl@0
   791
#endif
sl@0
   792
            iterator1 begin () const {
sl@0
   793
                return (*this) ().find1 (1, 0, it2_);
sl@0
   794
            }
sl@0
   795
            BOOST_UBLAS_INLINE
sl@0
   796
#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
sl@0
   797
            typename self_type::
sl@0
   798
#endif
sl@0
   799
            iterator1 end () const {
sl@0
   800
                return (*this) ().find1 (1, (*this) ().size1 (), it2_);
sl@0
   801
            }
sl@0
   802
            BOOST_UBLAS_INLINE
sl@0
   803
#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
sl@0
   804
            typename self_type::
sl@0
   805
#endif
sl@0
   806
            reverse_iterator1 rbegin () const {
sl@0
   807
                return reverse_iterator1 (end ());
sl@0
   808
            }
sl@0
   809
            BOOST_UBLAS_INLINE
sl@0
   810
#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
sl@0
   811
            typename self_type::
sl@0
   812
#endif
sl@0
   813
            reverse_iterator1 rend () const {
sl@0
   814
                return reverse_iterator1 (begin ());
sl@0
   815
            }
sl@0
   816
#endif
sl@0
   817
sl@0
   818
            // Indices
sl@0
   819
            BOOST_UBLAS_INLINE
sl@0
   820
            size_type index1 () const {
sl@0
   821
                return it1_;
sl@0
   822
            }
sl@0
   823
            BOOST_UBLAS_INLINE
sl@0
   824
            size_type index2 () const {
sl@0
   825
                return it2_;
sl@0
   826
            }
sl@0
   827
sl@0
   828
            // Assignment
sl@0
   829
            BOOST_UBLAS_INLINE
sl@0
   830
            iterator2 &operator = (const iterator2 &it) {
sl@0
   831
                container_reference<self_type>::assign (&it ());
sl@0
   832
                it1_ = it.it1_;
sl@0
   833
                it2_ = it.it2_;
sl@0
   834
                return *this;
sl@0
   835
            }
sl@0
   836
sl@0
   837
            // Comparison
sl@0
   838
            BOOST_UBLAS_INLINE
sl@0
   839
            bool operator == (const iterator2 &it) const {
sl@0
   840
                BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
sl@0
   841
                BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ());
sl@0
   842
                return it2_ == it.it2_;
sl@0
   843
            }
sl@0
   844
            BOOST_UBLAS_INLINE
sl@0
   845
            bool operator < (const iterator2 &it) const {
sl@0
   846
                BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
sl@0
   847
                BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ());
sl@0
   848
                return it2_ < it.it2_;
sl@0
   849
            }
sl@0
   850
sl@0
   851
        private:
sl@0
   852
            size_type it1_;
sl@0
   853
            size_type it2_;
sl@0
   854
sl@0
   855
            friend class const_iterator2;
sl@0
   856
        };
sl@0
   857
#endif
sl@0
   858
sl@0
   859
        BOOST_UBLAS_INLINE
sl@0
   860
        iterator2 begin2 () {
sl@0
   861
            return find2 (0, 0, 0);
sl@0
   862
        }
sl@0
   863
        BOOST_UBLAS_INLINE
sl@0
   864
        iterator2 end2 () {
sl@0
   865
            return find2 (0, 0, size_);
sl@0
   866
        }
sl@0
   867
sl@0
   868
        // Reverse iterators
sl@0
   869
sl@0
   870
        BOOST_UBLAS_INLINE
sl@0
   871
        const_reverse_iterator1 rbegin1 () const {
sl@0
   872
            return const_reverse_iterator1 (end1 ());
sl@0
   873
        }
sl@0
   874
        BOOST_UBLAS_INLINE
sl@0
   875
        const_reverse_iterator1 rend1 () const {
sl@0
   876
            return const_reverse_iterator1 (begin1 ());
sl@0
   877
        }
sl@0
   878
sl@0
   879
        BOOST_UBLAS_INLINE
sl@0
   880
        reverse_iterator1 rbegin1 () {
sl@0
   881
            return reverse_iterator1 (end1 ());
sl@0
   882
        }
sl@0
   883
        BOOST_UBLAS_INLINE
sl@0
   884
        reverse_iterator1 rend1 () {
sl@0
   885
            return reverse_iterator1 (begin1 ());
sl@0
   886
        }
sl@0
   887
sl@0
   888
        BOOST_UBLAS_INLINE
sl@0
   889
        const_reverse_iterator2 rbegin2 () const {
sl@0
   890
            return const_reverse_iterator2 (end2 ());
sl@0
   891
        }
sl@0
   892
        BOOST_UBLAS_INLINE
sl@0
   893
        const_reverse_iterator2 rend2 () const {
sl@0
   894
            return const_reverse_iterator2 (begin2 ());
sl@0
   895
        }
sl@0
   896
sl@0
   897
        BOOST_UBLAS_INLINE
sl@0
   898
        reverse_iterator2 rbegin2 () {
sl@0
   899
            return reverse_iterator2 (end2 ());
sl@0
   900
        }
sl@0
   901
        BOOST_UBLAS_INLINE
sl@0
   902
        reverse_iterator2 rend2 () {
sl@0
   903
            return reverse_iterator2 (begin2 ());
sl@0
   904
        }
sl@0
   905
sl@0
   906
    private:
sl@0
   907
        size_type size_;
sl@0
   908
        array_type data_;
sl@0
   909
    };
sl@0
   910
sl@0
   911
sl@0
   912
    // Symmetric matrix adaptor class
sl@0
   913
    template<class M, class TRI>
sl@0
   914
    class symmetric_adaptor:
sl@0
   915
        public matrix_expression<symmetric_adaptor<M, TRI> > {
sl@0
   916
sl@0
   917
        typedef symmetric_adaptor<M, TRI> self_type;
sl@0
   918
    public:
sl@0
   919
#ifdef BOOST_UBLAS_ENABLE_PROXY_SHORTCUTS
sl@0
   920
        using matrix_expression<self_type>::operator ();
sl@0
   921
#endif
sl@0
   922
        typedef const M const_matrix_type;
sl@0
   923
        typedef M matrix_type;
sl@0
   924
        typedef TRI triangular_type;
sl@0
   925
        typedef typename M::size_type size_type;
sl@0
   926
        typedef typename M::difference_type difference_type;
sl@0
   927
        typedef typename M::value_type value_type;
sl@0
   928
        typedef typename M::const_reference const_reference;
sl@0
   929
        typedef typename boost::mpl::if_<boost::is_const<M>,
sl@0
   930
                                          typename M::const_reference,
sl@0
   931
                                          typename M::reference>::type reference;
sl@0
   932
        typedef typename boost::mpl::if_<boost::is_const<M>,
sl@0
   933
                                          typename M::const_closure_type,
sl@0
   934
                                          typename M::closure_type>::type matrix_closure_type;
sl@0
   935
        typedef const self_type const_closure_type;
sl@0
   936
        typedef self_type closure_type;
sl@0
   937
        // Replaced by _temporary_traits to avoid type requirements on M
sl@0
   938
        //typedef typename M::vector_temporary_type vector_temporary_type;
sl@0
   939
        //typedef typename M::matrix_temporary_type matrix_temporary_type;
sl@0
   940
        typedef typename storage_restrict_traits<typename M::storage_category,
sl@0
   941
                                                 packed_proxy_tag>::storage_category storage_category;
sl@0
   942
        typedef typename M::orientation_category orientation_category;
sl@0
   943
sl@0
   944
        // Construction and destruction
sl@0
   945
        BOOST_UBLAS_INLINE
sl@0
   946
        symmetric_adaptor (matrix_type &data):
sl@0
   947
            matrix_expression<self_type> (),
sl@0
   948
            data_ (data) {
sl@0
   949
            BOOST_UBLAS_CHECK (data_.size1 () == data_.size2 (), bad_size ());
sl@0
   950
        }
sl@0
   951
        BOOST_UBLAS_INLINE
sl@0
   952
        symmetric_adaptor (const symmetric_adaptor &m):
sl@0
   953
            matrix_expression<self_type> (),
sl@0
   954
            data_ (m.data_) {
sl@0
   955
            BOOST_UBLAS_CHECK (data_.size1 () == data_.size2 (), bad_size ());
sl@0
   956
        }
sl@0
   957
sl@0
   958
        // Accessors
sl@0
   959
        BOOST_UBLAS_INLINE
sl@0
   960
        size_type size1 () const {
sl@0
   961
            return data_.size1 ();
sl@0
   962
        }
sl@0
   963
        BOOST_UBLAS_INLINE
sl@0
   964
        size_type size2 () const {
sl@0
   965
            return data_.size2 ();
sl@0
   966
        }
sl@0
   967
sl@0
   968
        // Storage accessors
sl@0
   969
        BOOST_UBLAS_INLINE
sl@0
   970
        const matrix_closure_type &data () const {
sl@0
   971
            return data_;
sl@0
   972
        }
sl@0
   973
        BOOST_UBLAS_INLINE
sl@0
   974
        matrix_closure_type &data () {
sl@0
   975
            return data_;
sl@0
   976
        }
sl@0
   977
sl@0
   978
        // Element access
sl@0
   979
#ifndef BOOST_UBLAS_PROXY_CONST_MEMBER
sl@0
   980
        BOOST_UBLAS_INLINE
sl@0
   981
        const_reference operator () (size_type i, size_type j) const {
sl@0
   982
            BOOST_UBLAS_CHECK (i < size1 (), bad_index ());
sl@0
   983
            BOOST_UBLAS_CHECK (j < size2 (), bad_index ());
sl@0
   984
            if (triangular_type::other (i, j))
sl@0
   985
                return data () (i, j);
sl@0
   986
            else
sl@0
   987
                return data () (j, i);
sl@0
   988
        }
sl@0
   989
        BOOST_UBLAS_INLINE
sl@0
   990
        reference operator () (size_type i, size_type j) {
sl@0
   991
            BOOST_UBLAS_CHECK (i < size1 (), bad_index ());
sl@0
   992
            BOOST_UBLAS_CHECK (j < size2 (), bad_index ());
sl@0
   993
            if (triangular_type::other (i, j))
sl@0
   994
                return data () (i, j);
sl@0
   995
            else
sl@0
   996
                return data () (j, i);
sl@0
   997
        }
sl@0
   998
#else
sl@0
   999
        BOOST_UBLAS_INLINE
sl@0
  1000
        reference operator () (size_type i, size_type j) const {
sl@0
  1001
            BOOST_UBLAS_CHECK (i < size1 (), bad_index ());
sl@0
  1002
            BOOST_UBLAS_CHECK (j < size2 (), bad_index ());
sl@0
  1003
            if (triangular_type::other (i, j))
sl@0
  1004
                return data () (i, j);
sl@0
  1005
            else
sl@0
  1006
                return data () (j, i);
sl@0
  1007
        }
sl@0
  1008
#endif
sl@0
  1009
sl@0
  1010
        // Assignment
sl@0
  1011
        BOOST_UBLAS_INLINE
sl@0
  1012
        symmetric_adaptor &operator = (const symmetric_adaptor &m) {
sl@0
  1013
            matrix_assign<scalar_assign, triangular_type> (*this, m);
sl@0
  1014
            return *this;
sl@0
  1015
        }
sl@0
  1016
        BOOST_UBLAS_INLINE
sl@0
  1017
        symmetric_adaptor &assign_temporary (symmetric_adaptor &m) {
sl@0
  1018
            *this = m;
sl@0
  1019
            return *this;
sl@0
  1020
        }
sl@0
  1021
        template<class AE>
sl@0
  1022
        BOOST_UBLAS_INLINE
sl@0
  1023
        symmetric_adaptor &operator = (const matrix_expression<AE> &ae) {
sl@0
  1024
            matrix_assign<scalar_assign, triangular_type> (*this, matrix<value_type> (ae));
sl@0
  1025
            return *this;
sl@0
  1026
        }
sl@0
  1027
        template<class AE>
sl@0
  1028
        BOOST_UBLAS_INLINE
sl@0
  1029
        symmetric_adaptor &assign (const matrix_expression<AE> &ae) {
sl@0
  1030
            matrix_assign<scalar_assign, triangular_type> (*this, ae);
sl@0
  1031
            return *this;
sl@0
  1032
        }
sl@0
  1033
        template<class AE>
sl@0
  1034
        BOOST_UBLAS_INLINE
sl@0
  1035
        symmetric_adaptor& operator += (const matrix_expression<AE> &ae) {
sl@0
  1036
            matrix_assign<scalar_assign, triangular_type> (*this, matrix<value_type> (*this + ae));
sl@0
  1037
            return *this;
sl@0
  1038
        }
sl@0
  1039
        template<class AE>
sl@0
  1040
        BOOST_UBLAS_INLINE
sl@0
  1041
        symmetric_adaptor &plus_assign (const matrix_expression<AE> &ae) {
sl@0
  1042
            matrix_assign<scalar_plus_assign, triangular_type> (*this, ae);
sl@0
  1043
            return *this;
sl@0
  1044
        }
sl@0
  1045
        template<class AE>
sl@0
  1046
        BOOST_UBLAS_INLINE
sl@0
  1047
        symmetric_adaptor& operator -= (const matrix_expression<AE> &ae) {
sl@0
  1048
            matrix_assign<scalar_assign, triangular_type> (*this, matrix<value_type> (*this - ae));
sl@0
  1049
            return *this;
sl@0
  1050
        }
sl@0
  1051
        template<class AE>
sl@0
  1052
        BOOST_UBLAS_INLINE
sl@0
  1053
        symmetric_adaptor &minus_assign (const matrix_expression<AE> &ae) {
sl@0
  1054
            matrix_assign<scalar_minus_assign, triangular_type> (*this, ae);
sl@0
  1055
            return *this;
sl@0
  1056
        }
sl@0
  1057
        template<class AT>
sl@0
  1058
        BOOST_UBLAS_INLINE
sl@0
  1059
        symmetric_adaptor& operator *= (const AT &at) {
sl@0
  1060
            matrix_assign_scalar<scalar_multiplies_assign> (*this, at);
sl@0
  1061
            return *this;
sl@0
  1062
        }
sl@0
  1063
        template<class AT>
sl@0
  1064
        BOOST_UBLAS_INLINE
sl@0
  1065
        symmetric_adaptor& operator /= (const AT &at) {
sl@0
  1066
            matrix_assign_scalar<scalar_divides_assign> (*this, at);
sl@0
  1067
            return *this;
sl@0
  1068
        }
sl@0
  1069
sl@0
  1070
        // Closure comparison
sl@0
  1071
        BOOST_UBLAS_INLINE
sl@0
  1072
        bool same_closure (const symmetric_adaptor &sa) const {
sl@0
  1073
            return (*this).data ().same_closure (sa.data ());
sl@0
  1074
       }
sl@0
  1075
sl@0
  1076
        // Swapping
sl@0
  1077
        BOOST_UBLAS_INLINE
sl@0
  1078
        void swap (symmetric_adaptor &m) {
sl@0
  1079
            if (this != &m)
sl@0
  1080
                matrix_swap<scalar_swap, triangular_type> (*this, m);
sl@0
  1081
        }
sl@0
  1082
        BOOST_UBLAS_INLINE
sl@0
  1083
        friend void swap (symmetric_adaptor &m1, symmetric_adaptor &m2) {
sl@0
  1084
            m1.swap (m2);
sl@0
  1085
        }
sl@0
  1086
sl@0
  1087
        // Iterator types
sl@0
  1088
    private:
sl@0
  1089
        // Use matrix iterator
sl@0
  1090
        typedef typename M::const_iterator1 const_subiterator1_type;
sl@0
  1091
        typedef typename boost::mpl::if_<boost::is_const<M>,
sl@0
  1092
                                          typename M::const_iterator1,
sl@0
  1093
                                          typename M::iterator1>::type subiterator1_type;
sl@0
  1094
        typedef typename M::const_iterator2 const_subiterator2_type;
sl@0
  1095
        typedef typename boost::mpl::if_<boost::is_const<M>,
sl@0
  1096
                                          typename M::const_iterator2,
sl@0
  1097
                                          typename M::iterator2>::type subiterator2_type;
sl@0
  1098
sl@0
  1099
    public:
sl@0
  1100
#ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR
sl@0
  1101
        typedef indexed_iterator1<self_type, packed_random_access_iterator_tag> iterator1;
sl@0
  1102
        typedef indexed_iterator2<self_type, packed_random_access_iterator_tag> iterator2;
sl@0
  1103
        typedef indexed_const_iterator1<self_type, dense_random_access_iterator_tag> const_iterator1;
sl@0
  1104
        typedef indexed_const_iterator2<self_type, dense_random_access_iterator_tag> const_iterator2;
sl@0
  1105
#else
sl@0
  1106
        class const_iterator1;
sl@0
  1107
        class iterator1;
sl@0
  1108
        class const_iterator2;
sl@0
  1109
        class iterator2;
sl@0
  1110
#endif
sl@0
  1111
        typedef reverse_iterator_base1<const_iterator1> const_reverse_iterator1;
sl@0
  1112
        typedef reverse_iterator_base1<iterator1> reverse_iterator1;
sl@0
  1113
        typedef reverse_iterator_base2<const_iterator2> const_reverse_iterator2;
sl@0
  1114
        typedef reverse_iterator_base2<iterator2> reverse_iterator2;
sl@0
  1115
sl@0
  1116
        // Element lookup
sl@0
  1117
        BOOST_UBLAS_INLINE
sl@0
  1118
        const_iterator1 find1 (int rank, size_type i, size_type j) const {
sl@0
  1119
            if (triangular_type::other (i, j)) {
sl@0
  1120
                if (triangular_type::other (size1 (), j)) {
sl@0
  1121
                    return const_iterator1 (*this, 0, 0,
sl@0
  1122
                                            data ().find1 (rank, i, j), data ().find1 (rank, size1 (), j),
sl@0
  1123
                                            data ().find2 (rank, size2 (), size1 ()), data ().find2 (rank, size2 (), size1 ()));
sl@0
  1124
                } else {
sl@0
  1125
                    return const_iterator1 (*this, 0, 1,
sl@0
  1126
                                            data ().find1 (rank, i, j), data ().find1 (rank, j, j),
sl@0
  1127
                                            data ().find2 (rank, j, j), data ().find2 (rank, j, size1 ()));
sl@0
  1128
                }
sl@0
  1129
            } else {
sl@0
  1130
                if (triangular_type::other (size1 (), j)) {
sl@0
  1131
                    return const_iterator1 (*this, 1, 0,
sl@0
  1132
                                            data ().find1 (rank, j, j), data ().find1 (rank, size1 (), j),
sl@0
  1133
                                            data ().find2 (rank, j, i), data ().find2 (rank, j, j));
sl@0
  1134
                } else {
sl@0
  1135
                    return const_iterator1 (*this, 1, 1,
sl@0
  1136
                                            data ().find1 (rank, size1 (), size2 ()), data ().find1 (rank, size1 (), size2 ()),
sl@0
  1137
                                            data ().find2 (rank, j, i), data ().find2 (rank, j, size1 ()));
sl@0
  1138
                }
sl@0
  1139
            }
sl@0
  1140
        }
sl@0
  1141
        BOOST_UBLAS_INLINE
sl@0
  1142
        iterator1 find1 (int rank, size_type i, size_type j) {
sl@0
  1143
            if (rank == 1)
sl@0
  1144
                i = triangular_type::mutable_restrict1 (i, j);
sl@0
  1145
            return iterator1 (*this, data ().find1 (rank, i, j));
sl@0
  1146
        }
sl@0
  1147
        BOOST_UBLAS_INLINE
sl@0
  1148
        const_iterator2 find2 (int rank, size_type i, size_type j) const {
sl@0
  1149
            if (triangular_type::other (i, j)) {
sl@0
  1150
                if (triangular_type::other (i, size2 ())) {
sl@0
  1151
                    return const_iterator2 (*this, 1, 1,
sl@0
  1152
                                            data ().find1 (rank, size2 (), size1 ()), data ().find1 (rank, size2 (), size1 ()),
sl@0
  1153
                                            data ().find2 (rank, i, j), data ().find2 (rank, i, size2 ()));
sl@0
  1154
                } else {
sl@0
  1155
                    return const_iterator2 (*this, 1, 0,
sl@0
  1156
                                            data ().find1 (rank, i, i), data ().find1 (rank, size2 (), i),
sl@0
  1157
                                            data ().find2 (rank, i, j), data ().find2 (rank, i, i));
sl@0
  1158
                }
sl@0
  1159
            } else {
sl@0
  1160
                if (triangular_type::other (i, size2 ())) {
sl@0
  1161
                    return const_iterator2 (*this, 0, 1,
sl@0
  1162
                                            data ().find1 (rank, j, i), data ().find1 (rank, i, i),
sl@0
  1163
                                            data ().find2 (rank, i, i), data ().find2 (rank, i, size2 ()));
sl@0
  1164
                } else {
sl@0
  1165
                    return const_iterator2 (*this, 0, 0,
sl@0
  1166
                                            data ().find1 (rank, j, i), data ().find1 (rank, size2 (), i),
sl@0
  1167
                                            data ().find2 (rank, size1 (), size2 ()), data ().find2 (rank, size2 (), size2 ()));
sl@0
  1168
                }
sl@0
  1169
            }
sl@0
  1170
        }
sl@0
  1171
        BOOST_UBLAS_INLINE
sl@0
  1172
        iterator2 find2 (int rank, size_type i, size_type j) {
sl@0
  1173
            if (rank == 1)
sl@0
  1174
                j = triangular_type::mutable_restrict2 (i, j);
sl@0
  1175
            return iterator2 (*this, data ().find2 (rank, i, j));
sl@0
  1176
        }
sl@0
  1177
sl@0
  1178
        // Iterators simply are indices.
sl@0
  1179
sl@0
  1180
#ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
sl@0
  1181
        class const_iterator1:
sl@0
  1182
            public container_const_reference<symmetric_adaptor>,
sl@0
  1183
            public random_access_iterator_base<typename iterator_restrict_traits<
sl@0
  1184
                                                   typename const_subiterator1_type::iterator_category, dense_random_access_iterator_tag>::iterator_category,
sl@0
  1185
                                               const_iterator1, value_type> {
sl@0
  1186
        public:
sl@0
  1187
            typedef typename const_subiterator1_type::value_type value_type;
sl@0
  1188
            typedef typename const_subiterator1_type::difference_type difference_type;
sl@0
  1189
            typedef typename const_subiterator1_type::reference reference;
sl@0
  1190
            typedef typename const_subiterator1_type::pointer pointer;
sl@0
  1191
sl@0
  1192
            typedef const_iterator2 dual_iterator_type;
sl@0
  1193
            typedef const_reverse_iterator2 dual_reverse_iterator_type;
sl@0
  1194
sl@0
  1195
            // Construction and destruction
sl@0
  1196
            BOOST_UBLAS_INLINE
sl@0
  1197
            const_iterator1 ():
sl@0
  1198
                container_const_reference<self_type> (),
sl@0
  1199
                begin_ (-1), end_ (-1), current_ (-1),
sl@0
  1200
                it1_begin_ (), it1_end_ (), it1_ (),
sl@0
  1201
                it2_begin_ (), it2_end_ (), it2_ () {}
sl@0
  1202
            BOOST_UBLAS_INLINE
sl@0
  1203
            const_iterator1 (const self_type &m, int begin, int end,
sl@0
  1204
                             const const_subiterator1_type &it1_begin, const const_subiterator1_type &it1_end,
sl@0
  1205
                             const const_subiterator2_type &it2_begin, const const_subiterator2_type &it2_end):
sl@0
  1206
                container_const_reference<self_type> (m),
sl@0
  1207
                begin_ (begin), end_ (end), current_ (begin),
sl@0
  1208
                it1_begin_ (it1_begin), it1_end_ (it1_end), it1_ (it1_begin_),
sl@0
  1209
                it2_begin_ (it2_begin), it2_end_ (it2_end), it2_ (it2_begin_) {
sl@0
  1210
                if (current_ == 0 && it1_ == it1_end_)
sl@0
  1211
                    current_ = 1;
sl@0
  1212
                if (current_ == 1 && it2_ == it2_end_)
sl@0
  1213
                    current_ = 0;
sl@0
  1214
                if ((current_ == 0 && it1_ == it1_end_) ||
sl@0
  1215
                    (current_ == 1 && it2_ == it2_end_))
sl@0
  1216
                    current_ = end_;
sl@0
  1217
                BOOST_UBLAS_CHECK (current_ == end_ ||
sl@0
  1218
                                   (current_ == 0 && it1_ != it1_end_) ||
sl@0
  1219
                                   (current_ == 1 && it2_ != it2_end_), internal_logic ());
sl@0
  1220
            }
sl@0
  1221
            // FIXME cannot compile
sl@0
  1222
            //  iterator1 does not have these members!
sl@0
  1223
            BOOST_UBLAS_INLINE
sl@0
  1224
            const_iterator1 (const iterator1 &it):
sl@0
  1225
                container_const_reference<self_type> (it ()),
sl@0
  1226
                begin_ (it.begin_), end_ (it.end_), current_ (it.current_),
sl@0
  1227
                it1_begin_ (it.it1_begin_), it1_end_ (it.it1_end_), it1_ (it.it1_),
sl@0
  1228
                it2_begin_ (it.it2_begin_), it2_end_ (it.it2_end_), it2_ (it.it2_) {
sl@0
  1229
                BOOST_UBLAS_CHECK (current_ == end_ ||
sl@0
  1230
                                   (current_ == 0 && it1_ != it1_end_) ||
sl@0
  1231
                                   (current_ == 1 && it2_ != it2_end_), internal_logic ());
sl@0
  1232
            }
sl@0
  1233
sl@0
  1234
            // Arithmetic
sl@0
  1235
            BOOST_UBLAS_INLINE
sl@0
  1236
            const_iterator1 &operator ++ () {
sl@0
  1237
                BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ());
sl@0
  1238
                if (current_ == 0) {
sl@0
  1239
                    BOOST_UBLAS_CHECK (it1_ != it1_end_, internal_logic ());
sl@0
  1240
                    ++ it1_;
sl@0
  1241
                    if (it1_ == it1_end_ && end_ == 1) {
sl@0
  1242
                        it2_ = it2_begin_;
sl@0
  1243
                        current_ = 1;
sl@0
  1244
                    }
sl@0
  1245
                } else /* if (current_ == 1) */ {
sl@0
  1246
                    BOOST_UBLAS_CHECK (it2_ != it2_end_, internal_logic ());
sl@0
  1247
                    ++ it2_;
sl@0
  1248
                    if (it2_ == it2_end_ && end_ == 0) {
sl@0
  1249
                        it1_ = it1_begin_;
sl@0
  1250
                        current_ = 0;
sl@0
  1251
                    }
sl@0
  1252
                }
sl@0
  1253
                return *this;
sl@0
  1254
            }
sl@0
  1255
            BOOST_UBLAS_INLINE
sl@0
  1256
            const_iterator1 &operator -- () {
sl@0
  1257
                BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ());
sl@0
  1258
                if (current_ == 0) {
sl@0
  1259
                    if (it1_ == it1_begin_ && begin_ == 1) {
sl@0
  1260
                        it2_ = it2_end_;
sl@0
  1261
                        BOOST_UBLAS_CHECK (it2_ != it2_begin_, internal_logic ());
sl@0
  1262
                        -- it2_;
sl@0
  1263
                        current_ = 1;
sl@0
  1264
                    } else {
sl@0
  1265
                        -- it1_;
sl@0
  1266
                    }
sl@0
  1267
                } else /* if (current_ == 1) */ {
sl@0
  1268
                    if (it2_ == it2_begin_ && begin_ == 0) {
sl@0
  1269
                        it1_ = it1_end_;
sl@0
  1270
                        BOOST_UBLAS_CHECK (it1_ != it1_begin_, internal_logic ());
sl@0
  1271
                        -- it1_;
sl@0
  1272
                        current_ = 0;
sl@0
  1273
                    } else {
sl@0
  1274
                        -- it2_;
sl@0
  1275
                    }
sl@0
  1276
                }
sl@0
  1277
                return *this;
sl@0
  1278
            }
sl@0
  1279
            BOOST_UBLAS_INLINE
sl@0
  1280
            const_iterator1 &operator += (difference_type n) {
sl@0
  1281
                BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ());
sl@0
  1282
                if (current_ == 0) {
sl@0
  1283
                    size_type d = (std::min) (n, it1_end_ - it1_);
sl@0
  1284
                    it1_ += d;
sl@0
  1285
                    n -= d;
sl@0
  1286
                    if (n > 0 || (end_ == 1 && it1_ == it1_end_)) {
sl@0
  1287
                        BOOST_UBLAS_CHECK (end_ == 1, external_logic ());
sl@0
  1288
                        d = (std::min) (n, it2_end_ - it2_begin_);
sl@0
  1289
                        it2_ = it2_begin_ + d;
sl@0
  1290
                        n -= d;
sl@0
  1291
                        current_ = 1;
sl@0
  1292
                    }
sl@0
  1293
                } else /* if (current_ == 1) */ {
sl@0
  1294
                    size_type d = (std::min) (n, it2_end_ - it2_);
sl@0
  1295
                    it2_ += d;
sl@0
  1296
                    n -= d;
sl@0
  1297
                    if (n > 0 || (end_ == 0 && it2_ == it2_end_)) {
sl@0
  1298
                        BOOST_UBLAS_CHECK (end_ == 0, external_logic ());
sl@0
  1299
                        d = (std::min) (n, it1_end_ - it1_begin_);
sl@0
  1300
                        it1_ = it1_begin_ + d;
sl@0
  1301
                        n -= d;
sl@0
  1302
                        current_ = 0;
sl@0
  1303
                    }
sl@0
  1304
                }
sl@0
  1305
                BOOST_UBLAS_CHECK (n == 0, external_logic ());
sl@0
  1306
                return *this;
sl@0
  1307
            }
sl@0
  1308
            BOOST_UBLAS_INLINE
sl@0
  1309
            const_iterator1 &operator -= (difference_type n) {
sl@0
  1310
                BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ());
sl@0
  1311
                if (current_ == 0) {
sl@0
  1312
                    size_type d = (std::min) (n, it1_ - it1_begin_);
sl@0
  1313
                    it1_ -= d;
sl@0
  1314
                    n -= d;
sl@0
  1315
                    if (n > 0) {
sl@0
  1316
                        BOOST_UBLAS_CHECK (end_ == 1, external_logic ());
sl@0
  1317
                        d = (std::min) (n, it2_end_ - it2_begin_);
sl@0
  1318
                        it2_ = it2_end_ - d;
sl@0
  1319
                        n -= d;
sl@0
  1320
                        current_ = 1;
sl@0
  1321
                    }
sl@0
  1322
                } else /* if (current_ == 1) */ {
sl@0
  1323
                    size_type d = (std::min) (n, it2_ - it2_begin_);
sl@0
  1324
                    it2_ -= d;
sl@0
  1325
                    n -= d;
sl@0
  1326
                    if (n > 0) {
sl@0
  1327
                        BOOST_UBLAS_CHECK (end_ == 0, external_logic ());
sl@0
  1328
                        d = (std::min) (n, it1_end_ - it1_begin_);
sl@0
  1329
                        it1_ = it1_end_ - d;
sl@0
  1330
                        n -= d;
sl@0
  1331
                        current_ = 0;
sl@0
  1332
                    }
sl@0
  1333
                }
sl@0
  1334
                BOOST_UBLAS_CHECK (n == 0, external_logic ());
sl@0
  1335
                return *this;
sl@0
  1336
            }
sl@0
  1337
            BOOST_UBLAS_INLINE
sl@0
  1338
            difference_type operator - (const const_iterator1 &it) const {
sl@0
  1339
                BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
sl@0
  1340
                BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ());
sl@0
  1341
                BOOST_UBLAS_CHECK (it.current_ == 0 || it.current_ == 1, internal_logic ());
sl@0
  1342
                BOOST_UBLAS_CHECK (/* begin_ == it.begin_ && */ end_ == it.end_, internal_logic ());
sl@0
  1343
                if (current_ == 0 && it.current_ == 0) {
sl@0
  1344
                    return it1_ - it.it1_;
sl@0
  1345
                } else if (current_ == 0 && it.current_ == 1) {
sl@0
  1346
                    if (end_ == 1 && it.end_ == 1) {
sl@0
  1347
                        return (it1_ - it.it1_end_) + (it.it2_begin_ - it.it2_);
sl@0
  1348
                    } else /* if (end_ == 0 && it.end_ == 0) */ {
sl@0
  1349
                        return (it1_ - it.it1_begin_) + (it.it2_end_ - it.it2_);
sl@0
  1350
                    }
sl@0
  1351
sl@0
  1352
                } else if (current_ == 1 && it.current_ == 0) {
sl@0
  1353
                    if (end_ == 1 && it.end_ == 1) {
sl@0
  1354
                        return (it2_ - it.it2_begin_) + (it.it1_end_ - it.it1_);
sl@0
  1355
                    } else /* if (end_ == 0 && it.end_ == 0) */ {
sl@0
  1356
                        return (it2_ - it.it2_end_) + (it.it1_begin_ - it.it1_);
sl@0
  1357
                    }
sl@0
  1358
                }
sl@0
  1359
                /* current_ == 1 && it.current_ == 1 */ {
sl@0
  1360
                    return it2_ - it.it2_;
sl@0
  1361
                }
sl@0
  1362
            }
sl@0
  1363
sl@0
  1364
            // Dereference
sl@0
  1365
            BOOST_UBLAS_INLINE
sl@0
  1366
            const_reference operator * () const {
sl@0
  1367
                BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ());
sl@0
  1368
                if (current_ == 0) {
sl@0
  1369
                    BOOST_UBLAS_CHECK (it1_ != it1_end_, internal_logic ());
sl@0
  1370
                    return *it1_;
sl@0
  1371
                } else /* if (current_ == 1) */ {
sl@0
  1372
                    BOOST_UBLAS_CHECK (it2_ != it2_end_, internal_logic ());
sl@0
  1373
                    return *it2_;
sl@0
  1374
                }
sl@0
  1375
            }
sl@0
  1376
            BOOST_UBLAS_INLINE
sl@0
  1377
            const_reference operator [] (difference_type n) const {
sl@0
  1378
                return *(*this + n);
sl@0
  1379
            }
sl@0
  1380
sl@0
  1381
#ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
sl@0
  1382
            BOOST_UBLAS_INLINE
sl@0
  1383
#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
sl@0
  1384
            typename self_type::
sl@0
  1385
#endif
sl@0
  1386
            const_iterator2 begin () const {
sl@0
  1387
                return (*this) ().find2 (1, index1 (), 0);
sl@0
  1388
            }
sl@0
  1389
            BOOST_UBLAS_INLINE
sl@0
  1390
#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
sl@0
  1391
            typename self_type::
sl@0
  1392
#endif
sl@0
  1393
            const_iterator2 end () const {
sl@0
  1394
                return (*this) ().find2 (1, index1 (), (*this) ().size2 ());
sl@0
  1395
            }
sl@0
  1396
            BOOST_UBLAS_INLINE
sl@0
  1397
#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
sl@0
  1398
            typename self_type::
sl@0
  1399
#endif
sl@0
  1400
            const_reverse_iterator2 rbegin () const {
sl@0
  1401
                return const_reverse_iterator2 (end ());
sl@0
  1402
            }
sl@0
  1403
            BOOST_UBLAS_INLINE
sl@0
  1404
#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
sl@0
  1405
            typename self_type::
sl@0
  1406
#endif
sl@0
  1407
            const_reverse_iterator2 rend () const {
sl@0
  1408
                return const_reverse_iterator2 (begin ());
sl@0
  1409
            }
sl@0
  1410
#endif
sl@0
  1411
sl@0
  1412
            // Indices
sl@0
  1413
            BOOST_UBLAS_INLINE
sl@0
  1414
            size_type index1 () const {
sl@0
  1415
                BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ());
sl@0
  1416
                if (current_ == 0) {
sl@0
  1417
                    BOOST_UBLAS_CHECK (it1_ != it1_end_, internal_logic ());
sl@0
  1418
                    return it1_.index1 ();
sl@0
  1419
                } else /* if (current_ == 1) */ {
sl@0
  1420
                    BOOST_UBLAS_CHECK (it2_ != it2_end_, internal_logic ());
sl@0
  1421
                    return it2_.index2 ();
sl@0
  1422
                }
sl@0
  1423
            }
sl@0
  1424
            BOOST_UBLAS_INLINE
sl@0
  1425
            size_type index2 () const {
sl@0
  1426
                BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ());
sl@0
  1427
                if (current_ == 0) {
sl@0
  1428
                    BOOST_UBLAS_CHECK (it1_ != it1_end_, internal_logic ());
sl@0
  1429
                    return it1_.index2 ();
sl@0
  1430
                } else /* if (current_ == 1) */ {
sl@0
  1431
                    BOOST_UBLAS_CHECK (it2_ != it2_end_, internal_logic ());
sl@0
  1432
                    return it2_.index1 ();
sl@0
  1433
                }
sl@0
  1434
            }
sl@0
  1435
sl@0
  1436
            // Assignment
sl@0
  1437
            BOOST_UBLAS_INLINE
sl@0
  1438
            const_iterator1 &operator = (const const_iterator1 &it) {
sl@0
  1439
                container_const_reference<self_type>::assign (&it ());
sl@0
  1440
                begin_ = it.begin_;
sl@0
  1441
                end_ = it.end_;
sl@0
  1442
                current_ = it.current_;
sl@0
  1443
                it1_begin_ = it.it1_begin_;
sl@0
  1444
                it1_end_ = it.it1_end_;
sl@0
  1445
                it1_ = it.it1_;
sl@0
  1446
                it2_begin_ = it.it2_begin_;
sl@0
  1447
                it2_end_ = it.it2_end_;
sl@0
  1448
                it2_ = it.it2_;
sl@0
  1449
                return *this;
sl@0
  1450
            }
sl@0
  1451
sl@0
  1452
            // Comparison
sl@0
  1453
            BOOST_UBLAS_INLINE
sl@0
  1454
            bool operator == (const const_iterator1 &it) const {
sl@0
  1455
                BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
sl@0
  1456
                BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ());
sl@0
  1457
                BOOST_UBLAS_CHECK (it.current_ == 0 || it.current_ == 1, internal_logic ());
sl@0
  1458
                BOOST_UBLAS_CHECK (/* begin_ == it.begin_ && */ end_ == it.end_, internal_logic ());
sl@0
  1459
                return (current_ == 0 && it.current_ == 0 && it1_ == it.it1_) ||
sl@0
  1460
                       (current_ == 1 && it.current_ == 1 && it2_ == it.it2_);
sl@0
  1461
            }
sl@0
  1462
            BOOST_UBLAS_INLINE
sl@0
  1463
            bool operator < (const const_iterator1 &it) const {
sl@0
  1464
                BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
sl@0
  1465
                return it - *this > 0;
sl@0
  1466
            }
sl@0
  1467
sl@0
  1468
        private:
sl@0
  1469
            int begin_;
sl@0
  1470
            int end_;
sl@0
  1471
            int current_;
sl@0
  1472
            const_subiterator1_type it1_begin_;
sl@0
  1473
            const_subiterator1_type it1_end_;
sl@0
  1474
            const_subiterator1_type it1_;
sl@0
  1475
            const_subiterator2_type it2_begin_;
sl@0
  1476
            const_subiterator2_type it2_end_;
sl@0
  1477
            const_subiterator2_type it2_;
sl@0
  1478
        };
sl@0
  1479
#endif
sl@0
  1480
sl@0
  1481
        BOOST_UBLAS_INLINE
sl@0
  1482
        const_iterator1 begin1 () const {
sl@0
  1483
            return find1 (0, 0, 0);
sl@0
  1484
        }
sl@0
  1485
        BOOST_UBLAS_INLINE
sl@0
  1486
        const_iterator1 end1 () const {
sl@0
  1487
            return find1 (0, size1 (), 0);
sl@0
  1488
        }
sl@0
  1489
sl@0
  1490
#ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
sl@0
  1491
        class iterator1:
sl@0
  1492
            public container_reference<symmetric_adaptor>,
sl@0
  1493
            public random_access_iterator_base<typename iterator_restrict_traits<
sl@0
  1494
                                                   typename subiterator1_type::iterator_category, packed_random_access_iterator_tag>::iterator_category,
sl@0
  1495
                                               iterator1, value_type> {
sl@0
  1496
        public:
sl@0
  1497
            typedef typename subiterator1_type::value_type value_type;
sl@0
  1498
            typedef typename subiterator1_type::difference_type difference_type;
sl@0
  1499
            typedef typename subiterator1_type::reference reference;
sl@0
  1500
            typedef typename subiterator1_type::pointer pointer;
sl@0
  1501
sl@0
  1502
            typedef iterator2 dual_iterator_type;
sl@0
  1503
            typedef reverse_iterator2 dual_reverse_iterator_type;
sl@0
  1504
sl@0
  1505
            // Construction and destruction
sl@0
  1506
            BOOST_UBLAS_INLINE
sl@0
  1507
            iterator1 ():
sl@0
  1508
                container_reference<self_type> (), it1_ () {}
sl@0
  1509
            BOOST_UBLAS_INLINE
sl@0
  1510
            iterator1 (self_type &m, const subiterator1_type &it1):
sl@0
  1511
                container_reference<self_type> (m), it1_ (it1) {}
sl@0
  1512
sl@0
  1513
            // Arithmetic
sl@0
  1514
            BOOST_UBLAS_INLINE
sl@0
  1515
            iterator1 &operator ++ () {
sl@0
  1516
                ++ it1_;
sl@0
  1517
                return *this;
sl@0
  1518
            }
sl@0
  1519
            BOOST_UBLAS_INLINE
sl@0
  1520
            iterator1 &operator -- () {
sl@0
  1521
                -- it1_;
sl@0
  1522
                return *this;
sl@0
  1523
            }
sl@0
  1524
            BOOST_UBLAS_INLINE
sl@0
  1525
            iterator1 &operator += (difference_type n) {
sl@0
  1526
                it1_ += n;
sl@0
  1527
                return *this;
sl@0
  1528
            }
sl@0
  1529
            BOOST_UBLAS_INLINE
sl@0
  1530
            iterator1 &operator -= (difference_type n) {
sl@0
  1531
                it1_ -= n;
sl@0
  1532
                return *this;
sl@0
  1533
            }
sl@0
  1534
            BOOST_UBLAS_INLINE
sl@0
  1535
            difference_type operator - (const iterator1 &it) const {
sl@0
  1536
                BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
sl@0
  1537
                return it1_ - it.it1_;
sl@0
  1538
            }
sl@0
  1539
sl@0
  1540
            // Dereference
sl@0
  1541
            BOOST_UBLAS_INLINE
sl@0
  1542
            reference operator * () const {
sl@0
  1543
                return *it1_;
sl@0
  1544
            }
sl@0
  1545
            BOOST_UBLAS_INLINE
sl@0
  1546
            reference operator [] (difference_type n) const {
sl@0
  1547
                return *(*this + n);
sl@0
  1548
            }
sl@0
  1549
sl@0
  1550
#ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
sl@0
  1551
            BOOST_UBLAS_INLINE
sl@0
  1552
#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
sl@0
  1553
            typename self_type::
sl@0
  1554
#endif
sl@0
  1555
            iterator2 begin () const {
sl@0
  1556
                return (*this) ().find2 (1, index1 (), 0);
sl@0
  1557
            }
sl@0
  1558
            BOOST_UBLAS_INLINE
sl@0
  1559
#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
sl@0
  1560
            typename self_type::
sl@0
  1561
#endif
sl@0
  1562
            iterator2 end () const {
sl@0
  1563
                return (*this) ().find2 (1, index1 (), (*this) ().size2 ());
sl@0
  1564
            }
sl@0
  1565
            BOOST_UBLAS_INLINE
sl@0
  1566
#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
sl@0
  1567
            typename self_type::
sl@0
  1568
#endif
sl@0
  1569
            reverse_iterator2 rbegin () const {
sl@0
  1570
                return reverse_iterator2 (end ());
sl@0
  1571
            }
sl@0
  1572
            BOOST_UBLAS_INLINE
sl@0
  1573
#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
sl@0
  1574
            typename self_type::
sl@0
  1575
#endif
sl@0
  1576
            reverse_iterator2 rend () const {
sl@0
  1577
                return reverse_iterator2 (begin ());
sl@0
  1578
            }
sl@0
  1579
#endif
sl@0
  1580
sl@0
  1581
            // Indices
sl@0
  1582
            BOOST_UBLAS_INLINE
sl@0
  1583
            size_type index1 () const {
sl@0
  1584
                return it1_.index1 ();
sl@0
  1585
            }
sl@0
  1586
            BOOST_UBLAS_INLINE
sl@0
  1587
            size_type index2 () const {
sl@0
  1588
                return it1_.index2 ();
sl@0
  1589
            }
sl@0
  1590
sl@0
  1591
            // Assignment
sl@0
  1592
            BOOST_UBLAS_INLINE
sl@0
  1593
            iterator1 &operator = (const iterator1 &it) {
sl@0
  1594
                container_reference<self_type>::assign (&it ());
sl@0
  1595
                it1_ = it.it1_;
sl@0
  1596
                return *this;
sl@0
  1597
            }
sl@0
  1598
sl@0
  1599
            // Comparison
sl@0
  1600
            BOOST_UBLAS_INLINE
sl@0
  1601
            bool operator == (const iterator1 &it) const {
sl@0
  1602
                BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
sl@0
  1603
                return it1_ == it.it1_;
sl@0
  1604
            }
sl@0
  1605
            BOOST_UBLAS_INLINE
sl@0
  1606
            bool operator < (const iterator1 &it) const {
sl@0
  1607
                BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
sl@0
  1608
                return it1_ < it.it1_;
sl@0
  1609
            }
sl@0
  1610
sl@0
  1611
        private:
sl@0
  1612
            subiterator1_type it1_;
sl@0
  1613
sl@0
  1614
            friend class const_iterator1;
sl@0
  1615
        };
sl@0
  1616
#endif
sl@0
  1617
sl@0
  1618
        BOOST_UBLAS_INLINE
sl@0
  1619
        iterator1 begin1 () {
sl@0
  1620
            return find1 (0, 0, 0);
sl@0
  1621
        }
sl@0
  1622
        BOOST_UBLAS_INLINE
sl@0
  1623
        iterator1 end1 () {
sl@0
  1624
            return find1 (0, size1 (), 0);
sl@0
  1625
        }
sl@0
  1626
sl@0
  1627
#ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
sl@0
  1628
        class const_iterator2:
sl@0
  1629
            public container_const_reference<symmetric_adaptor>,
sl@0
  1630
            public random_access_iterator_base<typename iterator_restrict_traits<
sl@0
  1631
                                                   typename const_subiterator2_type::iterator_category, dense_random_access_iterator_tag>::iterator_category,
sl@0
  1632
                                               const_iterator2, value_type> {
sl@0
  1633
        public:
sl@0
  1634
            typedef typename const_subiterator2_type::value_type value_type;
sl@0
  1635
            typedef typename const_subiterator2_type::difference_type difference_type;
sl@0
  1636
            typedef typename const_subiterator2_type::reference reference;
sl@0
  1637
            typedef typename const_subiterator2_type::pointer pointer;
sl@0
  1638
sl@0
  1639
            typedef const_iterator1 dual_iterator_type;
sl@0
  1640
            typedef const_reverse_iterator1 dual_reverse_iterator_type;
sl@0
  1641
sl@0
  1642
            // Construction and destruction
sl@0
  1643
            BOOST_UBLAS_INLINE
sl@0
  1644
            const_iterator2 ():
sl@0
  1645
                container_const_reference<self_type> (),
sl@0
  1646
                begin_ (-1), end_ (-1), current_ (-1),
sl@0
  1647
                it1_begin_ (), it1_end_ (), it1_ (),
sl@0
  1648
                it2_begin_ (), it2_end_ (), it2_ () {}
sl@0
  1649
            BOOST_UBLAS_INLINE
sl@0
  1650
            const_iterator2 (const self_type &m, int begin, int end,
sl@0
  1651
                             const const_subiterator1_type &it1_begin, const const_subiterator1_type &it1_end,
sl@0
  1652
                             const const_subiterator2_type &it2_begin, const const_subiterator2_type &it2_end):
sl@0
  1653
                container_const_reference<self_type> (m),
sl@0
  1654
                begin_ (begin), end_ (end), current_ (begin),
sl@0
  1655
                it1_begin_ (it1_begin), it1_end_ (it1_end), it1_ (it1_begin_),
sl@0
  1656
                it2_begin_ (it2_begin), it2_end_ (it2_end), it2_ (it2_begin_) {
sl@0
  1657
                if (current_ == 0 && it1_ == it1_end_)
sl@0
  1658
                    current_ = 1;
sl@0
  1659
                if (current_ == 1 && it2_ == it2_end_)
sl@0
  1660
                    current_ = 0;
sl@0
  1661
                if ((current_ == 0 && it1_ == it1_end_) ||
sl@0
  1662
                    (current_ == 1 && it2_ == it2_end_))
sl@0
  1663
                    current_ = end_;
sl@0
  1664
                BOOST_UBLAS_CHECK (current_ == end_ ||
sl@0
  1665
                                   (current_ == 0 && it1_ != it1_end_) ||
sl@0
  1666
                                   (current_ == 1 && it2_ != it2_end_), internal_logic ());
sl@0
  1667
            }
sl@0
  1668
            // FIXME cannot compiler
sl@0
  1669
            //  iterator2 does not have these members!
sl@0
  1670
            BOOST_UBLAS_INLINE
sl@0
  1671
            const_iterator2 (const iterator2 &it):
sl@0
  1672
                container_const_reference<self_type> (it ()),
sl@0
  1673
                begin_ (it.begin_), end_ (it.end_), current_ (it.current_),
sl@0
  1674
                it1_begin_ (it.it1_begin_), it1_end_ (it.it1_end_), it1_ (it.it1_),
sl@0
  1675
                it2_begin_ (it.it2_begin_), it2_end_ (it.it2_end_), it2_ (it.it2_) {
sl@0
  1676
                BOOST_UBLAS_CHECK (current_ == end_ ||
sl@0
  1677
                                   (current_ == 0 && it1_ != it1_end_) ||
sl@0
  1678
                                   (current_ == 1 && it2_ != it2_end_), internal_logic ());
sl@0
  1679
            }
sl@0
  1680
sl@0
  1681
            // Arithmetic
sl@0
  1682
            BOOST_UBLAS_INLINE
sl@0
  1683
            const_iterator2 &operator ++ () {
sl@0
  1684
                BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ());
sl@0
  1685
                if (current_ == 0) {
sl@0
  1686
                    BOOST_UBLAS_CHECK (it1_ != it1_end_, internal_logic ());
sl@0
  1687
                    ++ it1_;
sl@0
  1688
                    if (it1_ == it1_end_ && end_ == 1) {
sl@0
  1689
                        it2_ = it2_begin_;
sl@0
  1690
                        current_ = 1;
sl@0
  1691
                    }
sl@0
  1692
                } else /* if (current_ == 1) */ {
sl@0
  1693
                    BOOST_UBLAS_CHECK (it2_ != it2_end_, internal_logic ());
sl@0
  1694
                    ++ it2_;
sl@0
  1695
                    if (it2_ == it2_end_ && end_ == 0) {
sl@0
  1696
                        it1_ = it1_begin_;
sl@0
  1697
                        current_ = 0;
sl@0
  1698
                    }
sl@0
  1699
                }
sl@0
  1700
                return *this;
sl@0
  1701
            }
sl@0
  1702
            BOOST_UBLAS_INLINE
sl@0
  1703
            const_iterator2 &operator -- () {
sl@0
  1704
                BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ());
sl@0
  1705
                if (current_ == 0) {
sl@0
  1706
                    if (it1_ == it1_begin_ && begin_ == 1) {
sl@0
  1707
                        it2_ = it2_end_;
sl@0
  1708
                        BOOST_UBLAS_CHECK (it2_ != it2_begin_, internal_logic ());
sl@0
  1709
                        -- it2_;
sl@0
  1710
                        current_ = 1;
sl@0
  1711
                    } else {
sl@0
  1712
                        -- it1_;
sl@0
  1713
                    }
sl@0
  1714
                } else /* if (current_ == 1) */ {
sl@0
  1715
                    if (it2_ == it2_begin_ && begin_ == 0) {
sl@0
  1716
                        it1_ = it1_end_;
sl@0
  1717
                        BOOST_UBLAS_CHECK (it1_ != it1_begin_, internal_logic ());
sl@0
  1718
                        -- it1_;
sl@0
  1719
                        current_ = 0;
sl@0
  1720
                    } else {
sl@0
  1721
                        -- it2_;
sl@0
  1722
                    }
sl@0
  1723
                }
sl@0
  1724
                return *this;
sl@0
  1725
            }
sl@0
  1726
            BOOST_UBLAS_INLINE
sl@0
  1727
            const_iterator2 &operator += (difference_type n) {
sl@0
  1728
                BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ());
sl@0
  1729
                if (current_ == 0) {
sl@0
  1730
                    size_type d = (std::min) (n, it1_end_ - it1_);
sl@0
  1731
                    it1_ += d;
sl@0
  1732
                    n -= d;
sl@0
  1733
                    if (n > 0 || (end_ == 1 && it1_ == it1_end_)) {
sl@0
  1734
                        BOOST_UBLAS_CHECK (end_ == 1, external_logic ());
sl@0
  1735
                        d = (std::min) (n, it2_end_ - it2_begin_);
sl@0
  1736
                        it2_ = it2_begin_ + d;
sl@0
  1737
                        n -= d;
sl@0
  1738
                        current_ = 1;
sl@0
  1739
                    }
sl@0
  1740
                } else /* if (current_ == 1) */ {
sl@0
  1741
                    size_type d = (std::min) (n, it2_end_ - it2_);
sl@0
  1742
                    it2_ += d;
sl@0
  1743
                    n -= d;
sl@0
  1744
                    if (n > 0 || (end_ == 0 && it2_ == it2_end_)) {
sl@0
  1745
                        BOOST_UBLAS_CHECK (end_ == 0, external_logic ());
sl@0
  1746
                        d = (std::min) (n, it1_end_ - it1_begin_);
sl@0
  1747
                        it1_ = it1_begin_ + d;
sl@0
  1748
                        n -= d;
sl@0
  1749
                        current_ = 0;
sl@0
  1750
                    }
sl@0
  1751
                }
sl@0
  1752
                BOOST_UBLAS_CHECK (n == 0, external_logic ());
sl@0
  1753
                return *this;
sl@0
  1754
            }
sl@0
  1755
            BOOST_UBLAS_INLINE
sl@0
  1756
            const_iterator2 &operator -= (difference_type n) {
sl@0
  1757
                BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ());
sl@0
  1758
                if (current_ == 0) {
sl@0
  1759
                    size_type d = (std::min) (n, it1_ - it1_begin_);
sl@0
  1760
                    it1_ -= d;
sl@0
  1761
                    n -= d;
sl@0
  1762
                    if (n > 0) {
sl@0
  1763
                        BOOST_UBLAS_CHECK (end_ == 1, external_logic ());
sl@0
  1764
                        d = (std::min) (n, it2_end_ - it2_begin_);
sl@0
  1765
                        it2_ = it2_end_ - d;
sl@0
  1766
                        n -= d;
sl@0
  1767
                        current_ = 1;
sl@0
  1768
                    }
sl@0
  1769
                } else /* if (current_ == 1) */ {
sl@0
  1770
                    size_type d = (std::min) (n, it2_ - it2_begin_);
sl@0
  1771
                    it2_ -= d;
sl@0
  1772
                    n -= d;
sl@0
  1773
                    if (n > 0) {
sl@0
  1774
                        BOOST_UBLAS_CHECK (end_ == 0, external_logic ());
sl@0
  1775
                        d = (std::min) (n, it1_end_ - it1_begin_);
sl@0
  1776
                        it1_ = it1_end_ - d;
sl@0
  1777
                        n -= d;
sl@0
  1778
                        current_ = 0;
sl@0
  1779
                    }
sl@0
  1780
                }
sl@0
  1781
                BOOST_UBLAS_CHECK (n == 0, external_logic ());
sl@0
  1782
                return *this;
sl@0
  1783
            }
sl@0
  1784
            BOOST_UBLAS_INLINE
sl@0
  1785
            difference_type operator - (const const_iterator2 &it) const {
sl@0
  1786
                BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
sl@0
  1787
                BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ());
sl@0
  1788
                BOOST_UBLAS_CHECK (it.current_ == 0 || it.current_ == 1, internal_logic ());
sl@0
  1789
                BOOST_UBLAS_CHECK (/* begin_ == it.begin_ && */ end_ == it.end_, internal_logic ());
sl@0
  1790
                if (current_ == 0 && it.current_ == 0) {
sl@0
  1791
                    return it1_ - it.it1_;
sl@0
  1792
                } else if (current_ == 0 && it.current_ == 1) {
sl@0
  1793
                    if (end_ == 1 && it.end_ == 1) {
sl@0
  1794
                        return (it1_ - it.it1_end_) + (it.it2_begin_ - it.it2_);
sl@0
  1795
                    } else /* if (end_ == 0 && it.end_ == 0) */ {
sl@0
  1796
                        return (it1_ - it.it1_begin_) + (it.it2_end_ - it.it2_);
sl@0
  1797
                    }
sl@0
  1798
sl@0
  1799
                } else if (current_ == 1 && it.current_ == 0) {
sl@0
  1800
                    if (end_ == 1 && it.end_ == 1) {
sl@0
  1801
                        return (it2_ - it.it2_begin_) + (it.it1_end_ - it.it1_);
sl@0
  1802
                    } else /* if (end_ == 0 && it.end_ == 0) */ {
sl@0
  1803
                        return (it2_ - it.it2_end_) + (it.it1_begin_ - it.it1_);
sl@0
  1804
                    }
sl@0
  1805
                }
sl@0
  1806
                /* current_ == 1 && it.current_ == 1 */ {
sl@0
  1807
                    return it2_ - it.it2_;
sl@0
  1808
                }
sl@0
  1809
            }
sl@0
  1810
sl@0
  1811
            // Dereference
sl@0
  1812
            BOOST_UBLAS_INLINE
sl@0
  1813
            const_reference operator * () const {
sl@0
  1814
                BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ());
sl@0
  1815
                if (current_ == 0) {
sl@0
  1816
                    BOOST_UBLAS_CHECK (it1_ != it1_end_, internal_logic ());
sl@0
  1817
                    return *it1_;
sl@0
  1818
                } else /* if (current_ == 1) */ {
sl@0
  1819
                    BOOST_UBLAS_CHECK (it2_ != it2_end_, internal_logic ());
sl@0
  1820
                    return *it2_;
sl@0
  1821
                }
sl@0
  1822
            }
sl@0
  1823
            BOOST_UBLAS_INLINE
sl@0
  1824
            const_reference operator [] (difference_type n) const {
sl@0
  1825
                return *(*this + n);
sl@0
  1826
            }
sl@0
  1827
sl@0
  1828
#ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
sl@0
  1829
            BOOST_UBLAS_INLINE
sl@0
  1830
#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
sl@0
  1831
            typename self_type::
sl@0
  1832
#endif
sl@0
  1833
            const_iterator1 begin () const {
sl@0
  1834
                return (*this) ().find1 (1, 0, index2 ());
sl@0
  1835
            }
sl@0
  1836
            BOOST_UBLAS_INLINE
sl@0
  1837
#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
sl@0
  1838
            typename self_type::
sl@0
  1839
#endif
sl@0
  1840
            const_iterator1 end () const {
sl@0
  1841
                return (*this) ().find1 (1, (*this) ().size1 (), index2 ());
sl@0
  1842
            }
sl@0
  1843
            BOOST_UBLAS_INLINE
sl@0
  1844
#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
sl@0
  1845
            typename self_type::
sl@0
  1846
#endif
sl@0
  1847
            const_reverse_iterator1 rbegin () const {
sl@0
  1848
                return const_reverse_iterator1 (end ());
sl@0
  1849
            }
sl@0
  1850
            BOOST_UBLAS_INLINE
sl@0
  1851
#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
sl@0
  1852
            typename self_type::
sl@0
  1853
#endif
sl@0
  1854
            const_reverse_iterator1 rend () const {
sl@0
  1855
                return const_reverse_iterator1 (begin ());
sl@0
  1856
            }
sl@0
  1857
#endif
sl@0
  1858
sl@0
  1859
            // Indices
sl@0
  1860
            BOOST_UBLAS_INLINE
sl@0
  1861
            size_type index1 () const {
sl@0
  1862
                BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ());
sl@0
  1863
                if (current_ == 0) {
sl@0
  1864
                    BOOST_UBLAS_CHECK (it1_ != it1_end_, internal_logic ());
sl@0
  1865
                    return it1_.index2 ();
sl@0
  1866
                } else /* if (current_ == 1) */ {
sl@0
  1867
                    BOOST_UBLAS_CHECK (it2_ != it2_end_, internal_logic ());
sl@0
  1868
                    return it2_.index1 ();
sl@0
  1869
                }
sl@0
  1870
            }
sl@0
  1871
            BOOST_UBLAS_INLINE
sl@0
  1872
            size_type index2 () const {
sl@0
  1873
                BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ());
sl@0
  1874
                if (current_ == 0) {
sl@0
  1875
                    BOOST_UBLAS_CHECK (it1_ != it1_end_, internal_logic ());
sl@0
  1876
                    return it1_.index1 ();
sl@0
  1877
                } else /* if (current_ == 1) */ {
sl@0
  1878
                    BOOST_UBLAS_CHECK (it2_ != it2_end_, internal_logic ());
sl@0
  1879
                    return it2_.index2 ();
sl@0
  1880
                }
sl@0
  1881
            }
sl@0
  1882
sl@0
  1883
            // Assignment
sl@0
  1884
            BOOST_UBLAS_INLINE
sl@0
  1885
            const_iterator2 &operator = (const const_iterator2 &it) {
sl@0
  1886
                container_const_reference<self_type>::assign (&it ());
sl@0
  1887
                begin_ = it.begin_;
sl@0
  1888
                end_ = it.end_;
sl@0
  1889
                current_ = it.current_;
sl@0
  1890
                it1_begin_ = it.it1_begin_;
sl@0
  1891
                it1_end_ = it.it1_end_;
sl@0
  1892
                it1_ = it.it1_;
sl@0
  1893
                it2_begin_ = it.it2_begin_;
sl@0
  1894
                it2_end_ = it.it2_end_;
sl@0
  1895
                it2_ = it.it2_;
sl@0
  1896
                return *this;
sl@0
  1897
            }
sl@0
  1898
sl@0
  1899
            // Comparison
sl@0
  1900
            BOOST_UBLAS_INLINE
sl@0
  1901
            bool operator == (const const_iterator2 &it) const {
sl@0
  1902
                BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
sl@0
  1903
                BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ());
sl@0
  1904
                BOOST_UBLAS_CHECK (it.current_ == 0 || it.current_ == 1, internal_logic ());
sl@0
  1905
                BOOST_UBLAS_CHECK (/* begin_ == it.begin_ && */ end_ == it.end_, internal_logic ());
sl@0
  1906
                return (current_ == 0 && it.current_ == 0 && it1_ == it.it1_) ||
sl@0
  1907
                       (current_ == 1 && it.current_ == 1 && it2_ == it.it2_);
sl@0
  1908
            }
sl@0
  1909
            BOOST_UBLAS_INLINE
sl@0
  1910
            bool operator < (const const_iterator2 &it) const {
sl@0
  1911
                BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
sl@0
  1912
                return it - *this > 0;
sl@0
  1913
            }
sl@0
  1914
sl@0
  1915
        private:
sl@0
  1916
            int begin_;
sl@0
  1917
            int end_;
sl@0
  1918
            int current_;
sl@0
  1919
            const_subiterator1_type it1_begin_;
sl@0
  1920
            const_subiterator1_type it1_end_;
sl@0
  1921
            const_subiterator1_type it1_;
sl@0
  1922
            const_subiterator2_type it2_begin_;
sl@0
  1923
            const_subiterator2_type it2_end_;
sl@0
  1924
            const_subiterator2_type it2_;
sl@0
  1925
        };
sl@0
  1926
#endif
sl@0
  1927
sl@0
  1928
        BOOST_UBLAS_INLINE
sl@0
  1929
        const_iterator2 begin2 () const {
sl@0
  1930
            return find2 (0, 0, 0);
sl@0
  1931
        }
sl@0
  1932
        BOOST_UBLAS_INLINE
sl@0
  1933
        const_iterator2 end2 () const {
sl@0
  1934
            return find2 (0, 0, size2 ());
sl@0
  1935
        }
sl@0
  1936
sl@0
  1937
#ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
sl@0
  1938
        class iterator2:
sl@0
  1939
            public container_reference<symmetric_adaptor>,
sl@0
  1940
            public random_access_iterator_base<typename iterator_restrict_traits<
sl@0
  1941
                                                   typename subiterator2_type::iterator_category, packed_random_access_iterator_tag>::iterator_category,
sl@0
  1942
                                               iterator2, value_type> {
sl@0
  1943
        public:
sl@0
  1944
            typedef typename subiterator2_type::value_type value_type;
sl@0
  1945
            typedef typename subiterator2_type::difference_type difference_type;
sl@0
  1946
            typedef typename subiterator2_type::reference reference;
sl@0
  1947
            typedef typename subiterator2_type::pointer pointer;
sl@0
  1948
sl@0
  1949
            typedef iterator1 dual_iterator_type;
sl@0
  1950
            typedef reverse_iterator1 dual_reverse_iterator_type;
sl@0
  1951
sl@0
  1952
            // Construction and destruction
sl@0
  1953
            BOOST_UBLAS_INLINE
sl@0
  1954
            iterator2 ():
sl@0
  1955
                container_reference<self_type> (), it2_ () {}
sl@0
  1956
            BOOST_UBLAS_INLINE
sl@0
  1957
            iterator2 (self_type &m, const subiterator2_type &it2):
sl@0
  1958
                container_reference<self_type> (m), it2_ (it2) {}
sl@0
  1959
sl@0
  1960
            // Arithmetic
sl@0
  1961
            BOOST_UBLAS_INLINE
sl@0
  1962
            iterator2 &operator ++ () {
sl@0
  1963
                ++ it2_;
sl@0
  1964
                return *this;
sl@0
  1965
            }
sl@0
  1966
            BOOST_UBLAS_INLINE
sl@0
  1967
            iterator2 &operator -- () {
sl@0
  1968
                -- it2_;
sl@0
  1969
                return *this;
sl@0
  1970
            }
sl@0
  1971
            BOOST_UBLAS_INLINE
sl@0
  1972
            iterator2 &operator += (difference_type n) {
sl@0
  1973
                it2_ += n;
sl@0
  1974
                return *this;
sl@0
  1975
            }
sl@0
  1976
            BOOST_UBLAS_INLINE
sl@0
  1977
            iterator2 &operator -= (difference_type n) {
sl@0
  1978
                it2_ -= n;
sl@0
  1979
                return *this;
sl@0
  1980
            }
sl@0
  1981
            BOOST_UBLAS_INLINE
sl@0
  1982
            difference_type operator - (const iterator2 &it) const {
sl@0
  1983
                BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
sl@0
  1984
                return it2_ - it.it2_;
sl@0
  1985
            }
sl@0
  1986
sl@0
  1987
            // Dereference
sl@0
  1988
            BOOST_UBLAS_INLINE
sl@0
  1989
            reference operator * () const {
sl@0
  1990
                return *it2_;
sl@0
  1991
            }
sl@0
  1992
            BOOST_UBLAS_INLINE
sl@0
  1993
            reference operator [] (difference_type n) const {
sl@0
  1994
                return *(*this + n);
sl@0
  1995
            }
sl@0
  1996
sl@0
  1997
#ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
sl@0
  1998
            BOOST_UBLAS_INLINE
sl@0
  1999
#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
sl@0
  2000
            typename self_type::
sl@0
  2001
#endif
sl@0
  2002
            iterator1 begin () const {
sl@0
  2003
                return (*this) ().find1 (1, 0, index2 ());
sl@0
  2004
            }
sl@0
  2005
            BOOST_UBLAS_INLINE
sl@0
  2006
#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
sl@0
  2007
            typename self_type::
sl@0
  2008
#endif
sl@0
  2009
            iterator1 end () const {
sl@0
  2010
                return (*this) ().find1 (1, (*this) ().size1 (), index2 ());
sl@0
  2011
            }
sl@0
  2012
            BOOST_UBLAS_INLINE
sl@0
  2013
#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
sl@0
  2014
            typename self_type::
sl@0
  2015
#endif
sl@0
  2016
            reverse_iterator1 rbegin () const {
sl@0
  2017
                return reverse_iterator1 (end ());
sl@0
  2018
            }
sl@0
  2019
            BOOST_UBLAS_INLINE
sl@0
  2020
#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
sl@0
  2021
            typename self_type::
sl@0
  2022
#endif
sl@0
  2023
            reverse_iterator1 rend () const {
sl@0
  2024
                return reverse_iterator1 (begin ());
sl@0
  2025
            }
sl@0
  2026
#endif
sl@0
  2027
sl@0
  2028
            // Indices
sl@0
  2029
            BOOST_UBLAS_INLINE
sl@0
  2030
            size_type index1 () const {
sl@0
  2031
                return it2_.index1 ();
sl@0
  2032
            }
sl@0
  2033
            BOOST_UBLAS_INLINE
sl@0
  2034
            size_type index2 () const {
sl@0
  2035
                return it2_.index2 ();
sl@0
  2036
            }
sl@0
  2037
sl@0
  2038
            // Assignment
sl@0
  2039
            BOOST_UBLAS_INLINE
sl@0
  2040
            iterator2 &operator = (const iterator2 &it) {
sl@0
  2041
                container_reference<self_type>::assign (&it ());
sl@0
  2042
                it2_ = it.it2_;
sl@0
  2043
                return *this;
sl@0
  2044
            }
sl@0
  2045
sl@0
  2046
            // Comparison
sl@0
  2047
            BOOST_UBLAS_INLINE
sl@0
  2048
            bool operator == (const iterator2 &it) const {
sl@0
  2049
                BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
sl@0
  2050
                return it2_ == it.it2_;
sl@0
  2051
            }
sl@0
  2052
            BOOST_UBLAS_INLINE
sl@0
  2053
            bool operator < (const iterator2 &it) const {
sl@0
  2054
                BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
sl@0
  2055
                return it2_ < it.it2_;
sl@0
  2056
            }
sl@0
  2057
sl@0
  2058
        private:
sl@0
  2059
            subiterator2_type it2_;
sl@0
  2060
sl@0
  2061
            friend class const_iterator2;
sl@0
  2062
        };
sl@0
  2063
#endif
sl@0
  2064
sl@0
  2065
        BOOST_UBLAS_INLINE
sl@0
  2066
        iterator2 begin2 () {
sl@0
  2067
            return find2 (0, 0, 0);
sl@0
  2068
        }
sl@0
  2069
        BOOST_UBLAS_INLINE
sl@0
  2070
        iterator2 end2 () {
sl@0
  2071
            return find2 (0, 0, size2 ());
sl@0
  2072
        }
sl@0
  2073
sl@0
  2074
        // Reverse iterators
sl@0
  2075
sl@0
  2076
        BOOST_UBLAS_INLINE
sl@0
  2077
        const_reverse_iterator1 rbegin1 () const {
sl@0
  2078
            return const_reverse_iterator1 (end1 ());
sl@0
  2079
        }
sl@0
  2080
        BOOST_UBLAS_INLINE
sl@0
  2081
        const_reverse_iterator1 rend1 () const {
sl@0
  2082
            return const_reverse_iterator1 (begin1 ());
sl@0
  2083
        }
sl@0
  2084
sl@0
  2085
        BOOST_UBLAS_INLINE
sl@0
  2086
        reverse_iterator1 rbegin1 () {
sl@0
  2087
            return reverse_iterator1 (end1 ());
sl@0
  2088
        }
sl@0
  2089
        BOOST_UBLAS_INLINE
sl@0
  2090
        reverse_iterator1 rend1 () {
sl@0
  2091
            return reverse_iterator1 (begin1 ());
sl@0
  2092
        }
sl@0
  2093
sl@0
  2094
        BOOST_UBLAS_INLINE
sl@0
  2095
        const_reverse_iterator2 rbegin2 () const {
sl@0
  2096
            return const_reverse_iterator2 (end2 ());
sl@0
  2097
        }
sl@0
  2098
        BOOST_UBLAS_INLINE
sl@0
  2099
        const_reverse_iterator2 rend2 () const {
sl@0
  2100
            return const_reverse_iterator2 (begin2 ());
sl@0
  2101
        }
sl@0
  2102
sl@0
  2103
        BOOST_UBLAS_INLINE
sl@0
  2104
        reverse_iterator2 rbegin2 () {
sl@0
  2105
            return reverse_iterator2 (end2 ());
sl@0
  2106
        }
sl@0
  2107
        BOOST_UBLAS_INLINE
sl@0
  2108
        reverse_iterator2 rend2 () {
sl@0
  2109
            return reverse_iterator2 (begin2 ());
sl@0
  2110
        }
sl@0
  2111
sl@0
  2112
    private:
sl@0
  2113
        matrix_closure_type data_;
sl@0
  2114
    };
sl@0
  2115
sl@0
  2116
    // Specialization for temporary_traits
sl@0
  2117
    template <class M, class TRI>
sl@0
  2118
    struct vector_temporary_traits< symmetric_adaptor<M, TRI> >
sl@0
  2119
    : vector_temporary_traits< M > {} ;
sl@0
  2120
    template <class M, class TRI>
sl@0
  2121
    struct vector_temporary_traits< const symmetric_adaptor<M, TRI> >
sl@0
  2122
    : vector_temporary_traits< M > {} ;
sl@0
  2123
sl@0
  2124
    template <class M, class TRI>
sl@0
  2125
    struct matrix_temporary_traits< symmetric_adaptor<M, TRI> >
sl@0
  2126
    : matrix_temporary_traits< M > {} ;
sl@0
  2127
    template <class M, class TRI>
sl@0
  2128
    struct matrix_temporary_traits< const symmetric_adaptor<M, TRI> >
sl@0
  2129
    : matrix_temporary_traits< M > {} ;
sl@0
  2130
sl@0
  2131
}}}
sl@0
  2132
sl@0
  2133
#endif