template<typename T>
Matrix2 class

A simple 2D matrix class for linear algebra operations.

Template parameters
T The element type (typically float or double)

This class provides basic matrix operations including matrix-vector multiplication. It is implemented using std::vector of std::vector as the underlying storage.

Constructors, destructors, conversion operators

Matrix2(size_t rows, size_t cols)
Construct a matrix with specified dimensions.

Public functions

auto operator[](size_t i) -> std::vector<T>&
auto operator[](size_t i) const -> const std::vector<T>&
auto rows() const -> size_t
auto cols() const -> size_t
auto operator*(const Vector2<T>& v) const -> Vector2<T>

Function documentation

template<typename T>
Matrix2<T>::Matrix2(size_t rows, size_t cols)

Construct a matrix with specified dimensions.

Parameters
rows in The number of rows in the Matrix2
cols in The number of columns in the Matrix2

Creates a matrix with the given number of rows and columns, initializing all elements to the default value of type T.

template<typename T>
std::vector<T>& Matrix2<T>::operator[](size_t i)

Parameters
i The row index to access.
Returns A reference to the vector of elements at the specified row index.

Returns a reference to the vector of elements at the specified row index.

template<typename T>
const std::vector<T>& Matrix2<T>::operator[](size_t i) const

Parameters
i The row index to access.
Returns A constant reference to the vector of elements at the specified row index.

Returns a constant reference to the vector of elements at the specified row index.

template<typename T>
size_t Matrix2<T>::rows() const

Returns The number of rows in the Matrix2.

Returns the number of rows in the Matrix2.

template<typename T>
size_t Matrix2<T>::cols() const

Returns The number of columns in the Matrix2.

Returns the number of columns in the Matrix2.

template<typename T>
Vector2<T> Matrix2<T>::operator*(const Vector2<T>& v) const

Parameters
v The Vector2 to multiply by the elements of this Matrix2.
Returns The resulting Vector2 after the multiplication.

Multiplies the given Vector2 by the elements of this Matrix2.