From 721550d0f8d26421a8c0e39daec3215ce5411670 Mon Sep 17 00:00:00 2001 From: kallore Date: Mon, 19 May 2025 16:59:10 +0200 Subject: [PATCH] [ARITHMETIC OP][IMPLEMENTATION] rectifie dthe implementation of the unary - operator --- include/rotgen/impl/matrix_impl64.hpp | 2 +- include/rotgen/matrix.hpp | 6 ++++-- src/matrix_impl64.cpp | 3 +-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/include/rotgen/impl/matrix_impl64.hpp b/include/rotgen/impl/matrix_impl64.hpp index e814c7c..07a3fce 100644 --- a/include/rotgen/impl/matrix_impl64.hpp +++ b/include/rotgen/impl/matrix_impl64.hpp @@ -44,7 +44,7 @@ namespace rotgen matrix_impl64& operator+=(matrix_impl64 const& rhs); matrix_impl64& operator-=(matrix_impl64 const& rhs); - matrix_impl64& operator-(); + matrix_impl64 operator-() const; matrix_impl64& operator*=(matrix_impl64 const& rhs); matrix_impl64& operator*=(double d); matrix_impl64& operator/=(double d); diff --git a/include/rotgen/matrix.hpp b/include/rotgen/matrix.hpp index 6018b13..9c78d00 100644 --- a/include/rotgen/matrix.hpp +++ b/include/rotgen/matrix.hpp @@ -29,6 +29,8 @@ namespace rotgen if constexpr(Cols != -1) assert(c == Cols && "Mismatched between dynamic and static column size"); } + matrix(parent const& base) : parent(base) {} + matrix(std::initializer_list> init) : parent(init) { if constexpr(Rows != -1) assert(init.size() == Rows && "Mismatched between dynamic and static row size"); @@ -75,9 +77,9 @@ namespace rotgen return *this; } - matrix& operator-() + matrix operator-() const { - return static_cast(*this).operator-(); + return matrix(static_cast(*this).operator-()); } matrix& operator*=(matrix const& rhs) diff --git a/src/matrix_impl64.cpp b/src/matrix_impl64.cpp index a5a69ad..658b22c 100644 --- a/src/matrix_impl64.cpp +++ b/src/matrix_impl64.cpp @@ -101,8 +101,7 @@ namespace rotgen return *this; } - matrix_impl64& matrix_impl64::operator-() - { + matrix_impl64 matrix_impl64::operator-() const { matrix_impl64 result(*this); result.storage_->data = -result.storage_->data; return result;