From 53f57cb0a11c1839d9cb2352e6babdb13dc6b88a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Del=20Pino?= <stephane.delpino44@gmail.com> Date: Fri, 10 Sep 2021 19:18:21 +0200 Subject: [PATCH] Add meta-programming access to convenient static values These are TinyMatrix::Dimension TinyMatrix::NumberOfRows and TinyMatrix::NumberOfColumns Also add related tests --- src/algebra/TinyMatrix.hpp | 4 ++++ tests/test_TinyMatrix.cpp | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/algebra/TinyMatrix.hpp b/src/algebra/TinyMatrix.hpp index 0d3b9c0e5..e347650b3 100644 --- a/src/algebra/TinyMatrix.hpp +++ b/src/algebra/TinyMatrix.hpp @@ -14,6 +14,10 @@ template <size_t M, size_t N = M, typename T = double> class [[nodiscard]] TinyMatrix { public: + inline static constexpr size_t Dimension = M * N; + inline static constexpr size_t NumberOfRows = M; + inline static constexpr size_t NumberOfColumns = N; + using data_type = T; private: diff --git a/tests/test_TinyMatrix.cpp b/tests/test_TinyMatrix.cpp index c9b72d5de..81c187dc2 100644 --- a/tests/test_TinyMatrix.cpp +++ b/tests/test_TinyMatrix.cpp @@ -21,6 +21,16 @@ template class TinyMatrix<4, 4, double>; TEST_CASE("TinyMatrix", "[algebra]") { + REQUIRE(TinyMatrix<1, 1, int>::Dimension == 1); + REQUIRE(TinyMatrix<1, 1, int>::NumberOfRows == 1); + REQUIRE(TinyMatrix<1, 1, int>::NumberOfColumns == 1); + REQUIRE(TinyMatrix<2, 3, int>::Dimension == 6); + REQUIRE(TinyMatrix<2, 3, int>::NumberOfRows == 2); + REQUIRE(TinyMatrix<2, 3, int>::NumberOfColumns == 3); + REQUIRE(TinyMatrix<5, 4, int>::Dimension == 20); + REQUIRE(TinyMatrix<5, 4, int>::NumberOfRows == 5); + REQUIRE(TinyMatrix<5, 4, int>::NumberOfColumns == 4); + TinyMatrix<3, 4, int> A(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12); REQUIRE(((A(0, 0) == 1) and (A(0, 1) == 2) and (A(0, 2) == 3) and (A(0, 3) == 4) and // (A(1, 0) == 5) and (A(1, 1) == 6) and (A(1, 2) == 7) and (A(1, 3) == 8) and // -- GitLab