@@ -41,8 +41,8 @@ class NdMatrixProxy {
41
41
42
42
NdMatrixProxy<T, N>& operator =(const NdMatrixProxy<T, N>& other) = delete ;
43
43
44
- // /@brief const [] operator
45
- const NdMatrixProxy<T, N - 1 > operator [](size_t index) const {
44
+ // /@brief [] operator
45
+ NdMatrixProxy<T, N - 1 > operator [](size_t index) const {
46
46
VTR_ASSERT_SAFE_MSG (index < dim_sizes_[0 ], " Index out of range (above dimension maximum)" );
47
47
VTR_ASSERT_SAFE_MSG (dim_sizes_[1 ] > 0 , " Can not index into zero-sized dimension" );
48
48
@@ -53,12 +53,6 @@ class NdMatrixProxy {
53
53
start_ + dim_strides_[0 ] * index); // Advance to index in this dimension
54
54
}
55
55
56
- // /@brief [] operator
57
- NdMatrixProxy<T, N - 1 > operator [](size_t index) {
58
- // Call the const version and cast-away constness
59
- return const_cast <const NdMatrixProxy<T, N>*>(this )->operator [](index);
60
- }
61
-
62
56
private:
63
57
const size_t * dim_sizes_;
64
58
const size_t * dim_strides_;
@@ -83,21 +77,15 @@ class NdMatrixProxy<T, 1> {
83
77
84
78
NdMatrixProxy<T, 1 >& operator =(const NdMatrixProxy<T, 1 >& other) = delete ;
85
79
86
- // /@brief const [] operator
87
- const T& operator [](size_t index) const {
80
+ // /@brief [] operator
81
+ T& operator [](size_t index) const {
88
82
VTR_ASSERT_SAFE_MSG (dim_strides_[0 ] == 1 , " Final dimension must have stride 1" );
89
83
VTR_ASSERT_SAFE_MSG (index < dim_sizes_[0 ], " Index out of range (above dimension maximum)" );
90
84
91
85
// Base case
92
86
return start_[index];
93
87
}
94
88
95
- // /@brief [] operator
96
- T& operator [](size_t index) {
97
- // Call the const version and cast-away constness
98
- return const_cast <T&>(const_cast <const NdMatrixProxy<T, 1 >*>(this )->operator [](index));
99
- }
100
-
101
89
/* *
102
90
* @brief Backward compitability
103
91
*
@@ -107,16 +95,10 @@ class NdMatrixProxy<T, 1> {
107
95
* Note that it is the caller's responsibility to use this correctly; care must be taken
108
96
* not to clobber elements in other dimensions
109
97
*/
110
- const T* data () const {
98
+ T* data () const {
111
99
return start_;
112
100
}
113
101
114
- // /@brief same as above but allow update the value
115
- T* data () {
116
- // Call the const version and cast-away constness
117
- return const_cast <T*>(const_cast <const NdMatrixProxy<T, 1 >*>(this )->data ());
118
- }
119
-
120
102
private:
121
103
const size_t * dim_sizes_;
122
104
const size_t * dim_strides_;
@@ -203,14 +185,8 @@ class NdMatrixBase {
203
185
return dim_sizes_[i];
204
186
}
205
187
206
- // /@brief const Flat accessors of NdMatrix
207
- const T& get (size_t i) const {
208
- VTR_ASSERT_SAFE (i < size_);
209
- return data_[i];
210
- }
211
-
212
188
// /@brief Flat accessors of NdMatrix
213
- T& get (size_t i) {
189
+ T& get (size_t i) const {
214
190
VTR_ASSERT_SAFE (i < size_);
215
191
return data_[i];
216
192
}
@@ -344,13 +320,12 @@ class NdMatrix : public NdMatrixBase<T, N> {
344
320
// /@brief Use the base constructors
345
321
using NdMatrixBase<T, N>::NdMatrixBase;
346
322
347
- public:
348
323
/* *
349
324
* @brief Access an element
350
325
*
351
326
* Returns a proxy-object to allow chained array-style indexing (N >= 2 case)
352
327
*/
353
- const NdMatrixProxy<T, N - 1 > operator [](size_t index) const {
328
+ NdMatrixProxy<T, N - 1 > operator [](size_t index) const {
354
329
VTR_ASSERT_SAFE_MSG (this ->dim_size (0 ) > 0 , " Can not index into size zero dimension" );
355
330
VTR_ASSERT_SAFE_MSG (this ->dim_size (1 ) > 0 , " Can not index into size zero dimension" );
356
331
VTR_ASSERT_SAFE_MSG (index < this ->dim_sizes_ [0 ], " Index out of range (above dimension maximum)" );
@@ -361,16 +336,6 @@ class NdMatrix : public NdMatrixBase<T, N> {
361
336
this ->dim_strides_ .data () + 1 , // Pass the stride for the next dimension
362
337
this ->data_ .get () + this ->dim_strides_ [0 ] * index); // Advance to index in this dimension
363
338
}
364
-
365
- /* *
366
- * @brief Access an element
367
- *
368
- * Returns a proxy-object to allow chained array-style indexing
369
- */
370
- NdMatrixProxy<T, N - 1 > operator [](size_t index) {
371
- // Call the const version, since returned by value don't need to worry about const
372
- return const_cast <const NdMatrix<T, N>*>(this )->operator [](index);
373
- }
374
339
};
375
340
376
341
/* *
@@ -384,21 +349,14 @@ class NdMatrix<T, 1> : public NdMatrixBase<T, 1> {
384
349
// /@brief Use the base constructors
385
350
using NdMatrixBase<T, 1 >::NdMatrixBase;
386
351
387
- public:
388
- // /@brief Access an element (immutable)
389
- const T& operator [](size_t index) const {
352
+ // /@brief Access an element
353
+ T& operator [](size_t index) const {
390
354
VTR_ASSERT_SAFE_MSG (this ->dim_size (0 ) > 0 , " Can not index into size zero dimension" );
391
355
VTR_ASSERT_SAFE_MSG (index >= 0 , " Index out of range (below dimension minimum)" );
392
356
VTR_ASSERT_SAFE_MSG (index < this ->dim_sizes_ [0 ], " Index out of range (above dimension maximum)" );
393
357
394
358
return this ->data_ [index];
395
359
}
396
-
397
- // /@brief Access an element (mutable)
398
- T& operator [](size_t index) {
399
- // Call the const version, and cast away const-ness
400
- return const_cast <T&>(const_cast <const NdMatrix<T, 1 >*>(this )->operator [](index));
401
- }
402
360
};
403
361
404
362
// /@brief Convenient short forms for common NdMatricies
0 commit comments