Skip to content

Commit 76178d5

Browse files
author
XuhuaHuang
committed
Create dynamic_matrix.hpp
1 parent 9733bad commit 76178d5

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

MultiDimSpan/dynamic_matrix.hpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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

0 commit comments

Comments
 (0)