added operator square brackets

This commit is contained in:
2024-12-21 19:29:33 +03:00
parent 390e584aee
commit e497308349
2 changed files with 13 additions and 0 deletions

View File

@@ -66,6 +66,11 @@ namespace omath
m_data = other.m_data; m_data = other.m_data;
} }
OMATH_API constexpr Type& operator[](const size_t row, const size_t col)
{
return At(row, col);
}
OMATH_API constexpr Mat(Mat&& other) noexcept OMATH_API constexpr Mat(Mat&& other) noexcept
{ {
m_data = std::move(other.m_data); m_data = std::move(other.m_data);

View File

@@ -40,6 +40,14 @@ TEST_F(UnitTestMat, Constructor_InitializerList)
EXPECT_FLOAT_EQ(m.At(1, 1), 4.0f); EXPECT_FLOAT_EQ(m.At(1, 1), 4.0f);
} }
TEST_F(UnitTestMat, Operator_SquareBrackets)
{
EXPECT_EQ((m2[0, 0]), 1.0f);
EXPECT_EQ((m2[0, 1]), 2.0f);
EXPECT_EQ((m2[1, 0]), 3.0f);
EXPECT_EQ((m2[1, 1]), 4.0f);
}
TEST_F(UnitTestMat, Constructor_Copy) TEST_F(UnitTestMat, Constructor_Copy)
{ {
Mat<2, 2> m3 = m2; Mat<2, 2> m3 = m2;