#ifndef MATRIX_HPP #define MATRIX_HPP #include #include enum class StorageOrder {ColMajor, RowMajor}; struct Matrix { const std::size_t m; /* number of rows */ const std::size_t n; /* number of columns */ const std::size_t incRow; /* stride between subsequent rows */ const std::size_t incCol; /* stride between subsequent columns */ double* data; Matrix(std::size_t m, std::size_t n, StorageOrder order) : m(m), n(n), incRow(order == StorageOrder::ColMajor? 1: n), incCol(order == StorageOrder::RowMajor? 1: m), data(new double[m*n]) { } ~Matrix() { delete[] data; } Matrix(const Matrix&) = delete; Matrix& operator=(const Matrix&) = delete; const double& operator()(std::size_t i, std::size_t j) const { assert(i < m && j < n); return data[i*incRow + j*incCol]; } double& operator()(std::size_t i, std::size_t j) { assert(i < m && j < n); return data[i*incRow + j*incCol]; } }; #endif