From cbcb6aeb1510ee1bd2d67d9d0b285df67f7088b5 Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Sat, 5 Oct 2019 17:59:32 +0200 Subject: New matrix data model (breaks everything) --- include/mm/view.hpp | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 include/mm/view.hpp (limited to 'include/mm/view.hpp') diff --git a/include/mm/view.hpp b/include/mm/view.hpp new file mode 100644 index 0000000..910c16a --- /dev/null +++ b/include/mm/view.hpp @@ -0,0 +1,66 @@ +#pragma once + +#include + + +namespace mm::alg { + + template < + template typename Matrix, + typename T, std::size_t Rows, std::size_t Cols + > + struct visitor + { + using type = T; + + // copy constructible + visitor(const visitor& other) = default; + + T& operator()(const Matrix& m, index row, index col) { + return m.at(row, col); + } + + const T& operator()(const Matrix& m, index row, index col) { + return operator()(m, row, col); + } + }; + + template < + template typename Matrix, + typename T, std::size_t Rows, std::size_t Cols + > + struct transpose : public visitor + { + T& operator()(const Matrix m, index row, index col) { + // assert(col < Rows) + // assert(row < Cols) + return m.at(col, row); + } + }; +} + +namespace mm { + template < + template typename Matrix, + typename T, std::size_t Rows, std::size_t Cols + > + struct view + { + Matrix& m; + // std::stack> visitors; + std::unique_ptr visitor; + + T& at(index row, index col) { + return visitor(m, row, col); + } + + view& operator|=(const alg::visitor& other) { + // visitors.push(std::move(std::make_unique(other))); + visitor = std::make_unique(other); + } + }; + + view operator|(const view& left, const alg::visitor& right) { + return left |= right; + } +} -- cgit v1.2.1