How to deduce the two dimensions of a compile-time matrix class with an initializer_list constructor?
#include <iostream> #include <array> template <typename T, size_t Rows, size_t Cols> class Matrix { protected: std::array<std::array<T, Cols>, Rows> matrix; public: constexpr Matrix() = default; constexpr explicit Matrix(std::array<std::array<T, Cols>, Rows> matrix) : matrix(std::move(matrix)) { } consteval Matrix(std::initializer_list<std::initializer_list<T>> matrix) : matrix() { if (matrix.size() != Rows) { throw std::invalid_argument(“Invalid matrix Rows count”); } auto current_row = matrix.begin(); […]
How to deduce the two dimensions of a compile-time matrix class with an initializer_list constructor?
#include <iostream> #include <array> template <typename T, size_t Rows, size_t Cols> class Matrix { protected: std::array<std::array<T, Cols>, Rows> matrix; public: constexpr Matrix() = default; constexpr explicit Matrix(std::array<std::array<T, Cols>, Rows> matrix) : matrix(std::move(matrix)) { } consteval Matrix(std::initializer_list<std::initializer_list<T>> matrix) : matrix() { if (matrix.size() != Rows) { throw std::invalid_argument(“Invalid matrix Rows count”); } auto current_row = matrix.begin(); […]