diff --git a/src/Math/Matrix.h b/src/Math/Matrix.h index 16beaf05c..c524c877b 100644 --- a/src/Math/Matrix.h +++ b/src/Math/Matrix.h @@ -140,16 +140,16 @@ template class Matrix: public RectangularMatrix { inline Vector operator*(const Vector& other) const { return RectangularMatrix::operator*(other); } - #endif MAGNUM_RECTANGULARMATRIX_SUBCLASS_IMPLEMENTATION(size, size, Matrix) MAGNUM_RECTANGULARMATRIX_SUBCLASS_OPERATOR_IMPLEMENTATION(size, size, Matrix) + #endif }; #ifndef DOXYGEN_GENERATING_OUTPUT -template inline Matrix operator*(U number, const Matrix& matrix) { +template inline typename std::enable_if::value, Matrix>::type operator*(U number, const Matrix& matrix) { return number*RectangularMatrix(matrix); } -template inline Matrix operator/(U number, const Matrix& matrix) { +template inline typename std::enable_if::value, Matrix>::type operator/(U number, const Matrix& matrix) { return number/RectangularMatrix(matrix); } #endif @@ -190,7 +190,7 @@ template Corrade::Utility::Debug operator<<(Corrade::Utili Matrix::operator*=(other); \ return *this; \ } \ - template inline RectangularMatrix operator*(const RectangularMatrix& other) const { \ + template inline RectangularMatrix operator*(const RectangularMatrix& other) const { \ return Matrix::operator*(other); \ } \ inline VectorType operator*(const Vector& other) const { \ @@ -201,10 +201,10 @@ template Corrade::Utility::Debug operator<<(Corrade::Utili inline Type inverted() const { return Matrix::inverted(); } #define MAGNUM_MATRIX_SUBCLASS_OPERATOR_IMPLEMENTATION(Type, size) \ - template inline Type operator*(U number, const Type& matrix) { \ + template inline typename std::enable_if::value, Type>::type operator*(U number, const Type& matrix) { \ return number*Matrix(matrix); \ } \ - template inline Type operator/(U number, const Type& matrix) { \ + template inline typename std::enable_if::value, Type>::type operator/(U number, const Type& matrix) { \ return number/Matrix(matrix); \ } diff --git a/src/Math/Vector.h b/src/Math/Vector.h index 728ce8029..6776fcbd0 100644 --- a/src/Math/Vector.h +++ b/src/Math/Vector.h @@ -247,8 +247,14 @@ template class Vector: public RectangularMatrix<1, s, T> { return out; } + #ifndef DOXYGEN_GENERATING_OUTPUT + /* Reimplementation of functions to return correct type */ + template inline RectangularMatrix operator*(const RectangularMatrix& other) const { + return RectangularMatrix<1, size, T>::operator*(other); + } MAGNUM_RECTANGULARMATRIX_SUBCLASS_IMPLEMENTATION(1, size, Vector) MAGNUM_RECTANGULARMATRIX_SUBCLASS_OPERATOR_IMPLEMENTATION(1, size, Vector) + #endif private: /* Hiding unused things from RectangularMatrix */ @@ -259,10 +265,10 @@ template class Vector: public RectangularMatrix<1, s, T> { }; #ifndef DOXYGEN_GENERATING_OUTPUT -template inline Vector operator*(U number, const Vector& vector) { +template inline typename std::enable_if::value, Vector>::type operator*(U number, const Vector& vector) { return number*RectangularMatrix<1, size, T>(vector); } -template inline Vector operator/(U number, const Vector& vector) { +template inline typename std::enable_if::value, Vector>::type operator/(U number, const Vector& vector) { return number/RectangularMatrix<1, size, T>(vector); } #endif @@ -297,6 +303,9 @@ template Corrade::Utility::Debug operator<<(Corrade::Utili return *this; \ } \ \ + template inline Math::RectangularMatrix operator*(const Math::RectangularMatrix& other) const { \ + return Math::Vector::operator*(other); \ + } \ inline Type operator*(const Math::Vector& other) const { \ return Math::Vector::operator*(other); \ } \ @@ -316,10 +325,10 @@ template Corrade::Utility::Debug operator<<(Corrade::Utili inline Type normalized() const { return Math::Vector::normalized(); } #define MAGNUM_VECTOR_SUBCLASS_OPERATOR_IMPLEMENTATION(Type, size) \ - template inline Type operator*(U number, const Type& vector) { \ + template inline typename std::enable_if::value, Type>::type operator*(U number, const Type& vector) { \ return number*Math::Vector(vector); \ } \ - template inline Type operator/(U number, const Type& vector) { \ + template inline typename std::enable_if::value, Type>::type operator/(U number, const Type& vector) { \ return number/Math::Vector(vector); \ } #endif