File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ /* *
2+ * @file dynamic_matrix.hpp
3+ * @author Xuhua Huang
4+ * @brief
5+ * @version 0.1
6+ * @date 2025-06-07
7+ *
8+ * @copyright Copyright (c) 2025
9+ *
10+ */
11+
12+ #pragma once
13+ #ifndef DYNAMIC_MATRIX_HPP
14+ #define DYNAMIC_MATRIX_HPP
15+
16+ #include < vector>
17+
18+ template <typename T>
19+ struct dynamic_matrix {
20+ std::vector<T> data;
21+ std::size_t rows, cols;
22+
23+ dynamic_matrix (std::size_t r, std::size_t c)
24+ : data(r * c)
25+ , rows(r)
26+ , cols(c) {}
27+
28+ T& operator ()(std::size_t i, std::size_t j) { return data[i * cols + j]; }
29+
30+ const T& operator ()(std::size_t i, std::size_t j) const { return data[i * cols + j]; }
31+
32+ std::size_t num_rows () const { return rows; }
33+
34+ std::size_t num_cols () const { return cols; }
35+ };
36+
37+ #endif // !DYNAMIC_MATRIX_HPP
You can’t perform that action at this time.
0 commit comments