@@ -33,46 +33,72 @@ class MatrixRow : public VectorBase< RTYPE, true, MatrixRow<RTYPE> > {
33
33
typedef typename MATRIX::const_Proxy const_reference ;
34
34
typedef typename MATRIX::value_type value_type ;
35
35
36
- class iterator {
36
+ // We now have the structure to correct const-correctness, but without
37
+ // major changes to the proxy mechanism, we cannot do it correctly. As
38
+ // a result, it turns out that both MatrixRow iterators are effectively
39
+ // const, but this has always been the way it is so we won't break any
40
+ // compatibility. TODO: Fix proxies and make this const correct.
41
+ struct iter_traits
42
+ {
43
+ typedef typename traits::r_vector_iterator<RTYPE>::type vector_iterator;
44
+
45
+ typedef int difference_type;
46
+ typedef typename traits::r_vector_proxy<RTYPE>::type value_type;
47
+ typedef value_type reference;
48
+ typedef typename std::iterator_traits<vector_iterator>::pointer pointer;
49
+ };
50
+
51
+ struct const_iter_traits
52
+ {
53
+ typedef typename traits::r_vector_const_iterator<RTYPE>::type vector_iterator;
54
+
55
+ typedef int difference_type;
56
+ typedef typename traits::r_vector_proxy<RTYPE>::type value_type;
57
+ typedef value_type reference;
58
+ typedef typename std::iterator_traits<vector_iterator>::pointer pointer;
59
+ };
60
+
61
+ template < typename TRAITS >
62
+ class iter_base {
37
63
public:
38
- typedef typename traits::r_vector_iterator<RTYPE>::type vector_iterator ;
64
+ typedef typename TRAITS:: vector_iterator vector_iterator ;
39
65
40
- typedef int difference_type ;
41
- typedef typename traits::r_vector_proxy<RTYPE>::type value_type ;
42
- typedef typename traits::r_vector_proxy<RTYPE>::type reference ;
43
- typedef typename std::iterator_traits<vector_iterator> ::pointer pointer ;
66
+ typedef typename TRAITS::difference_type difference_type ;
67
+ typedef typename TRAITS::value_type value_type ;
68
+ typedef typename TRAITS::reference reference ;
69
+ typedef typename TRAITS ::pointer pointer ;
44
70
45
71
typedef std::random_access_iterator_tag iterator_category ;
46
72
47
- iterator ( const iterator & other) : row(other.row), index(other.index){}
48
- iterator ( MatrixRow& row_, int index_ ) : row(row_), index(index_){}
73
+ iter_base ( const iter_base & other) : row(other.row), index(other.index){}
74
+ iter_base ( MatrixRow& row_, int index_ ) : row(row_), index(index_){}
49
75
50
- iterator & operator ++(){
76
+ iter_base & operator ++(){
51
77
index++;
52
78
return *this ;
53
79
}
54
- iterator operator ++(int ) {
80
+ iter_base operator ++(int ) {
55
81
iterator orig (*this );
56
82
index++ ;
57
83
return orig ;
58
84
}
59
85
60
- iterator & operator --(){
86
+ iter_base & operator --(){
61
87
index-- ;
62
88
return *this ;
63
89
}
64
- iterator operator --(int ){
65
- iterator orig (*this );
90
+ iter_base operator --(int ){
91
+ iter_base orig (*this );
66
92
index-- ;
67
93
return orig ;
68
94
}
69
95
70
- iterator operator +(difference_type n) const { return iterator ( row, index + n ) ; }
71
- iterator operator -(difference_type n) const { return iterator ( row, index - n ) ; }
72
- difference_type operator -(const iterator & other) const { return index - other.index ; }
96
+ iter_base operator +(difference_type n) const { return iter_base ( row, index + n ) ; }
97
+ iter_base operator -(difference_type n) const { return iter_base ( row, index - n ) ; }
98
+ difference_type operator -(const iter_base & other) const { return index - other.index ; }
73
99
74
- iterator & operator +=(difference_type n) { index += n ; return *this ;}
75
- iterator & operator -=(difference_type n) { index -= n ; return *this ;}
100
+ iter_base & operator +=(difference_type n) { index += n ; return *this ;}
101
+ iter_base & operator -=(difference_type n) { index -= n ; return *this ;}
76
102
77
103
reference operator *() {
78
104
return row[index] ;
@@ -81,25 +107,28 @@ class MatrixRow : public VectorBase< RTYPE, true, MatrixRow<RTYPE> > {
81
107
return &row[index] ;
82
108
}
83
109
84
- bool operator ==( const iterator & other) { return index == other.index ; }
85
- bool operator !=( const iterator & other) { return index != other.index ; }
86
- bool operator <( const iterator & other ) { return index < other.index ;}
87
- bool operator >( const iterator & other ) { return index > other.index ;}
88
- bool operator <=( const iterator & other ) { return index <= other.index ; }
89
- bool operator >=( const iterator & other ) { return index >= other.index ; }
110
+ bool operator ==( const iter_base & other) { return index == other.index ; }
111
+ bool operator !=( const iter_base & other) { return index != other.index ; }
112
+ bool operator <( const iter_base & other ) { return index < other.index ;}
113
+ bool operator >( const iter_base & other ) { return index > other.index ;}
114
+ bool operator <=( const iter_base & other ) { return index <= other.index ; }
115
+ bool operator >=( const iter_base & other ) { return index >= other.index ; }
90
116
91
117
inline reference operator []( int i) const {
92
118
return row[ index + i ] ;
93
119
}
94
120
95
- difference_type operator -(const iterator & other) {
121
+ difference_type operator -(const iter_base & other) {
96
122
return index - other.index ;
97
123
}
98
124
99
125
private:
100
126
MatrixRow& row ;
101
127
int index ;
102
- } ;
128
+ };
129
+
130
+ typedef iter_base< iter_traits > iterator;
131
+ typedef iter_base< const_iter_traits > const_iterator;
103
132
104
133
MatrixRow ( MATRIX& object, int i ) :
105
134
parent (object),
@@ -151,12 +180,20 @@ class MatrixRow : public VectorBase< RTYPE, true, MatrixRow<RTYPE> > {
151
180
return iterator ( *this , size () ) ;
152
181
}
153
182
154
- inline iterator begin () const {
155
- return iterator ( const_cast <MatrixRow&>(*this ), 0 ) ;
183
+ inline const_iterator begin () const {
184
+ return const_iterator ( const_cast <MatrixRow&>(*this ), 0 ) ;
185
+ }
186
+
187
+ inline const_iterator end () const {
188
+ return const_iterator ( const_cast <MatrixRow&>(*this ), size () ) ;
189
+ }
190
+
191
+ inline const_iterator cbegin () const {
192
+ return const_iterator ( const_cast <MatrixRow&>(*this ), 0 ) ;
156
193
}
157
194
158
- inline iterator end () const {
159
- return iterator ( const_cast <MatrixRow&>(*this ), size () ) ;
195
+ inline const_iterator cend () const {
196
+ return const_iterator ( const_cast <MatrixRow&>(*this ), size () ) ;
160
197
}
161
198
162
199
inline int size () const {
0 commit comments