diff --git a/include/libcamera/internal/matrix.h b/include/libcamera/internal/matrix.h index b9c3d41ef..512c1162c 100644 --- a/include/libcamera/internal/matrix.h +++ b/include/libcamera/internal/matrix.h @@ -25,9 +25,8 @@ class Matrix static_assert(std::is_arithmetic_v, "Matrix type must be arithmetic"); public: - Matrix() + constexpr Matrix() { - data_.fill(static_cast(0)); } Matrix(const std::array &data) @@ -35,7 +34,7 @@ public: std::copy(data.begin(), data.end(), data_.begin()); } - static Matrix identity() + static constexpr Matrix identity() { Matrix ret; for (size_t i = 0; i < std::min(Rows, Cols); i++) @@ -63,14 +62,14 @@ public: return out.str(); } - Span data() const { return data_; } + constexpr Span data() const { return data_; } - Span operator[](size_t i) const + constexpr Span operator[](size_t i) const { return Span{ &data_.data()[i * Cols], Cols }; } - Span operator[](size_t i) + constexpr Span operator[](size_t i) { return Span{ &data_.data()[i * Cols], Cols }; } @@ -88,7 +87,12 @@ public: } private: - std::array data_; + /* + * \todo The initializer is only necessary for the constructor to be + * constexpr in C++17. Remove the initializer as soon as we are on + * C++20. + */ + std::array data_ = {}; }; #ifndef __DOXYGEN__ @@ -141,7 +145,7 @@ constexpr Matrix operator*(const Matrix &m1, const Matrix< } template -Matrix operator+(const Matrix &m1, const Matrix &m2) +constexpr Matrix operator+(const Matrix &m1, const Matrix &m2) { Matrix result;