добавил const для части контейнеров и explicit для конструкторов

This commit is contained in:
2023-07-03 19:10:36 +03:00
parent 9e78546b7e
commit 3a6b3a4064
10 changed files with 217 additions and 176 deletions

View File

@@ -98,12 +98,12 @@ public:
inline const T * data(size_t index = 0) const { return p_->data(st_ + index); }
inline Row & operator=(const Row & other) {
if (p_ == other.p_ && st_ == other.st_) return *this;
size_t sz = piMin<size_t>(sz_, other.sz_);
const size_t sz = piMin<size_t>(sz_, other.sz_);
p_->_copyRaw(p_->data(st_), other.data(), sz);
return *this;
}
inline Row & operator=(const PIVector<T> & other) {
size_t sz = piMin<size_t>(sz, other.size());
const size_t sz = piMin<size_t>(sz, other.size());
p_->_copyRaw(p_->data(st_), other.data(), sz);
return *this;
}
@@ -130,13 +130,13 @@ public:
inline const T * data(size_t index = 0) const { return p_->data(index * step_ + row_); }
inline Col & operator=(const Col & other) {
if (p_ == other.p_ && row_ == other.row_) return *this;
size_t sz = piMin<size_t>(sz_, other.sz_);
const size_t sz = piMin<size_t>(sz_, other.sz_);
for (int i = 0; i < sz; ++i)
(*p_)[i * step_ + row_] = other[i];
return *this;
}
inline Row & operator=(const PIVector<T> & other) {
size_t sz = piMin<size_t>(sz_, other.size());
const size_t sz = piMin<size_t>(sz_, other.size());
for (int i = 0; i < sz; ++i)
(*p_)[i * step_ + row_] = other[i];
return *this;
@@ -206,24 +206,24 @@ public:
inline Col col(size_t index) { return Col(this, index); }
inline ColConst col(size_t index) const { return ColConst(this, index); }
inline PIVector2D<T> & setRow(size_t row, const Row & other) {
size_t sz = piMin<size_t>(cols_, other.sz_);
const size_t sz = piMin<size_t>(cols_, other.sz_);
mat._copyRaw(mat.data(cols_ * row), other.data(), sz);
return *this;
}
inline PIVector2D<T> & setRow(size_t row, const RowConst & other) {
size_t sz = piMin<size_t>(cols_, other.sz_);
const size_t sz = piMin<size_t>(cols_, other.sz_);
mat._copyRaw(mat.data(cols_ * row), other.data(), sz);
return *this;
}
inline PIVector2D<T> & setRow(size_t row, const PIVector<T> & other) {
size_t sz = piMin<size_t>(cols_, other.size());
const size_t sz = piMin<size_t>(cols_, other.size());
mat._copyRaw(mat.data(cols_ * row), other.data(), sz);
return *this;
}
inline PIVector2D<T> & addRow(const Row & other) {
if (cols_ == 0) cols_ = other.sz_;
size_t sz = piMin<size_t>(cols_, other.sz_);
size_t ps = mat.size();
const size_t sz = piMin<size_t>(cols_, other.sz_);
const size_t ps = mat.size();
mat.resize(mat.size() + cols_);
mat._copyRaw(mat.data(ps), other.data(), sz);
rows_++;
@@ -231,8 +231,8 @@ public:
}
inline PIVector2D<T> & addRow(const RowConst & other) {
if (cols_ == 0) cols_ = other.sz_;
size_t sz = piMin<size_t>(cols_, other.sz_);
size_t ps = mat.size();
const size_t sz = piMin<size_t>(cols_, other.sz_);
const size_t ps = mat.size();
mat.resize(mat.size() + cols_);
mat._copyRaw(mat.data(ps), other.data(), sz);
rows_++;
@@ -240,8 +240,8 @@ public:
}
inline PIVector2D<T> & addRow(const PIVector<T> & other) {
if (cols_ == 0) cols_ = other.size();
size_t sz = piMin<size_t>(cols_, other.size());
size_t ps = mat.size();
const size_t sz = piMin<size_t>(cols_, other.size());
const size_t ps = mat.size();
mat.resize(mat.size() + cols_);
mat._copyRaw(mat.data(ps), other.data(), sz);
rows_++;
@@ -250,8 +250,8 @@ public:
inline PIVector2D<T> & resize(size_t rows, size_t cols, const T & f = T()) {
mat.resize(rows * cols_, f);
rows_ = rows;
int cs = (cols - cols_);
rows_ = rows;
const int cs = (cols - cols_);
if (cs < 0) {
for (size_t r = 0; r < rows; ++r) {
mat.remove(r * cols + cols, -cs);