From 223c486c92daffd66d2adc73d623cde18167dab4 Mon Sep 17 00:00:00 2001 From: hladu357 Date: Tue, 21 May 2024 18:32:26 +0200 Subject: [PATCH] generic matrix template --- m.cpp | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 m.cpp diff --git a/m.cpp b/m.cpp new file mode 100644 index 0000000..b5f7309 --- /dev/null +++ b/m.cpp @@ -0,0 +1,64 @@ +template struct Matrix; + +template +struct Matrix { + typedef T GenericDimType[FirstDim]; + + GenericDimType data; + inline T& operator[](unsigned i) { return data[i]; } +}; + +template +struct Matrix { + typedef typename Matrix::GenericDimType FirstDimType; + typedef FirstDimType GenericDimType[FirstDim]; + + GenericDimType data; + inline FirstDimType& operator[](unsigned i) { return data[i]; } +}; + + + + + + + + + +#include + +int main() { + Matrix m; + + int cnt = 0; + for (size_t i = 0; i < 2; ++i) { + for (size_t j = 0; j < 3; ++j) { + for (size_t h = 0; h < 4; ++h) { + m[i][j][h] = cnt++; + } + } + } + + std::cout << "Data in matrix:\n"; + for (size_t i = 0; i < 2; ++i) { + for (size_t j = 0; j < 3; ++j) { + for (size_t h = 0; h < 4; ++h) { + std::cout << m[i][j][h] << ' '; + } + std::cout << '\n'; + } + std::cout << "ENDDIM\n"; + } + + std::cout << "Addresses in matrix:\n"; + for (size_t i = 0; i < 2; ++i) { + for (size_t j = 0; j < 3; ++j) { + for (size_t h = 0; h < 4; ++h) { + std::cout << &m[i][j][h] << ' '; + } + std::cout << '\n'; + } + std::cout << "ENDDIM\n"; + } + return 0; +} \ No newline at end of file