Skip to content

Commit f2e8898

Browse files
committed
add mutable at and operator[]
1 parent 7f40e69 commit f2e8898

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

include/LinearAlgebra/StaticMatrix/Base/staticmatrix_base.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,17 @@ namespace klibrary::linear_algebra {
7979
const ElemT& operator[](const SizeT& i) const {
8080
return this->matrix_[i];
8181
}
82+
ElemT& operator[](const SizeT& i) {
83+
return this->matrix_[i];
84+
}
8285
const ElemT& at(const SizeT& i) const {
8386
assert(i < Rows * Cols);
8487
return this->matrix_[i];
8588
}
89+
ElemT& at(const SizeT& i) {
90+
assert(i < Rows * Cols);
91+
return this->matrix_[i];
92+
}
8693
constexpr MatrixBaseShape shape() const noexcept {
8794
return MatrixBaseShape(Rows, Cols);
8895
}

include/LinearAlgebra/StaticMatrix/staticmatrix.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,11 @@ ElemT& operator()(const SizeT& r, const SizeT& c);
170170
171171
```cpp
172172
const ElemT& operator[](const SizeT& i) const; // (1)
173+
ElemT& operator[](const SizeT& i); // (2)
173174
```
174175

175-
- (1) `this->matrix_[i];`を返す (境界チェックを行わない)
176+
- (1) 行列を1次元配列形式でみた際の変更不可能な要素を返す (境界チェックを行わない)
177+
- (2) 行列を1次元配列形式でみた際の変更可能な要素を返す (境界チェックを行わない)
176178

177179
#### 出力演算子
178180

@@ -186,15 +188,17 @@ std::ostream& operator<<(std::ostream& out, const StaticMatrixBase& input_matrix
186188

187189
```cpp
188190
const ElemT& at(const SizeT& i) const; // (1)
189-
constexpr MatrixBaseShape shape() const noexcept; // (2)
190-
void swap_rows(const SizeT& r1, const SizeT& r2); // (3)
191-
void swap_cols(const SizeT& c1, const SizeT& c2); // (4)
191+
ElemT& at(const SizeT& i); // (2)
192+
constexpr MatrixBaseShape shape() const noexcept; // (3)
193+
void swap_rows(const SizeT& r1, const SizeT& r2); // (4)
194+
void swap_cols(const SizeT& c1, const SizeT& c2); // (5)
192195
```
193196
194-
- (1) 行列を1次元配列形式でみた際の変更不可能な要素を返す
195-
- (2) 行列の形を取得する
196-
- (3) 第`r1`行と第`r2`行を入れ替える
197-
- (4) 第`c1`列と第`c2`列を入れ替える
197+
- (1) 行列を1次元配列形式でみた際の変更不可能な要素を返す (境界チェックを行う)
198+
- (2) 行列を1次元配列形式でみた際の変更可能な要素を返す (境界チェックを行う)
199+
- (3) 行列の形を取得する
200+
- (4) 第`r1`行と第`r2`行を入れ替える
201+
- (5) 第`c1`列と第`c2`列を入れ替える
198202
199203
行入れ替えと列入れ替えは約4倍程列入れ替えの方が遅い。
200204

0 commit comments

Comments
 (0)