From c6a0c1ca8d41faac8b01d479efda0f6469da09ac Mon Sep 17 00:00:00 2001 From: Sebastian Eibl <sebastian.eibl@fau.de> Date: Mon, 25 Jan 2021 13:31:50 +0100 Subject: [PATCH] [ADD] constexpr to constructors of Matrix2 and MatrixMxN --- src/core/math/Matrix2.h | 26 +++++++++++++------------- src/core/math/MatrixMxN.h | 20 ++++++++++---------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/core/math/Matrix2.h b/src/core/math/Matrix2.h index e3d889333..f8310899c 100644 --- a/src/core/math/Matrix2.h +++ b/src/core/math/Matrix2.h @@ -87,16 +87,16 @@ private: public: //**Constructors***************************************************************************************************** - explicit inline Matrix2(); - explicit inline Matrix2( Type init ); - explicit inline Matrix2( Type xx, Type xy, Type yx, Type yy ); - explicit inline Matrix2( const Type* init ); + explicit inline constexpr Matrix2(); + explicit inline constexpr Matrix2( Type init ); + explicit inline constexpr Matrix2( Type xx, Type xy, Type yx, Type yy ); + explicit inline constexpr Matrix2( const Type* init ); - inline Matrix2( const Matrix2& m ); + inline constexpr Matrix2( const Matrix2& m ); template< typename Other > - inline Matrix2( const Matrix2<Other>& m ); + inline constexpr Matrix2( const Matrix2<Other>& m ); //******************************************************************************************************************* //**Destructor******************************************************************************************************* @@ -189,7 +189,7 @@ private: // with 0. */ template< typename Type > -inline Matrix2<Type>::Matrix2() +inline constexpr Matrix2<Type>::Matrix2() { v_[0] = v_[3] = Type(1); v_[1] = v_[2] = Type(0); @@ -204,7 +204,7 @@ inline Matrix2<Type>::Matrix2() // \param init Initial value for all matrix elements. */ template< typename Type > -inline Matrix2<Type>::Matrix2( Type init ) +inline constexpr Matrix2<Type>::Matrix2( Type init ) { v_[0] = v_[1] = v_[2] = v_[3] = init; } @@ -221,8 +221,8 @@ inline Matrix2<Type>::Matrix2( Type init ) // \param yy The initial value for the yy-component. */ template< typename Type > -inline Matrix2<Type>::Matrix2( Type xx, Type xy, - Type yx, Type yy ) +inline constexpr Matrix2<Type>::Matrix2( Type xx, Type xy, + Type yx, Type yy ) { v_[0] = xx; v_[1] = xy; v_[2] = yx; v_[3] = yy; @@ -239,7 +239,7 @@ inline Matrix2<Type>::Matrix2( Type xx, Type xy, // The array is assumed to have at least nine valid elements. */ template< typename Type > -inline Matrix2<Type>::Matrix2( const Type* init ) +inline constexpr Matrix2<Type>::Matrix2( const Type* init ) { v_[0] = init[0]; v_[1] = init[1]; @@ -258,7 +258,7 @@ inline Matrix2<Type>::Matrix2( const Type* init ) // The copy constructor is explicitly defined in order to enable/facilitate NRV optimization. */ template< typename Type > -inline Matrix2<Type>::Matrix2( const Matrix2& m ) +inline constexpr Matrix2<Type>::Matrix2( const Matrix2& m ) { v_[0] = m.v_[0]; v_[1] = m.v_[1]; @@ -276,7 +276,7 @@ inline Matrix2<Type>::Matrix2( const Matrix2& m ) */ template< typename Type > template< typename Other > -inline Matrix2<Type>::Matrix2( const Matrix2<Other>& m ) +inline constexpr Matrix2<Type>::Matrix2( const Matrix2<Other>& m ) { v_[0] = m.v_[0]; v_[1] = m.v_[1]; diff --git a/src/core/math/MatrixMxN.h b/src/core/math/MatrixMxN.h index 70854e2b6..be490da34 100644 --- a/src/core/math/MatrixMxN.h +++ b/src/core/math/MatrixMxN.h @@ -105,13 +105,13 @@ public: //**Constructors******************************************************************************** /*!\name Constructors */ //@{ - explicit inline MatrixMxN(); - explicit inline MatrixMxN( size_t m, size_t n ); - explicit inline MatrixMxN( size_t m, size_t n, Type init ); - inline MatrixMxN( const MatrixMxN& m ); + explicit inline constexpr MatrixMxN(); + explicit inline constexpr MatrixMxN( size_t m, size_t n ); + explicit inline constexpr MatrixMxN( size_t m, size_t n, Type init ); + inline constexpr MatrixMxN( const MatrixMxN& m ); template< typename Other, size_t M, size_t N > - inline MatrixMxN( const Other (&rhs)[M][N] ); + inline constexpr MatrixMxN( const Other (&rhs)[M][N] ); //@} //********************************************************************************************** @@ -199,7 +199,7 @@ private: /*!\brief The default constructor for MatrixMxN. */ template< typename Type > // Data type of the matrix -inline MatrixMxN<Type>::MatrixMxN() +inline constexpr MatrixMxN<Type>::MatrixMxN() : m_ ( 0 ) // The current number of rows of the matrix , n_ ( 0 ) // The current number of columns of the matrix , capacity_( 0 ) // The maximum capacity of the matrix @@ -218,7 +218,7 @@ inline MatrixMxN<Type>::MatrixMxN() * element initialization is performed! */ template< typename Type > // Data type of the matrix -inline MatrixMxN<Type>::MatrixMxN( size_t m, size_t n ) +inline constexpr MatrixMxN<Type>::MatrixMxN( size_t m, size_t n ) : m_ ( m ) // The current number of rows of the matrix , n_ ( n ) // The current number of columns of the matrix , capacity_( m*n ) // The maximum capacity of the matrix @@ -237,7 +237,7 @@ inline MatrixMxN<Type>::MatrixMxN( size_t m, size_t n ) * All matrix elements are initialized with the specified value. */ template< typename Type > // Data type of the matrix -inline MatrixMxN<Type>::MatrixMxN( size_t m, size_t n, Type init ) +inline constexpr MatrixMxN<Type>::MatrixMxN( size_t m, size_t n, Type init ) : m_ ( m ) // The current number of rows of the matrix , n_ ( n ) // The current number of columns of the matrix , capacity_( m*n ) // The maximum capacity of the matrix @@ -258,7 +258,7 @@ inline MatrixMxN<Type>::MatrixMxN( size_t m, size_t n, Type init ) * and in order to enable/facilitate NRV optimization. */ template< typename Type > // Data type of the matrix -inline MatrixMxN<Type>::MatrixMxN( const MatrixMxN& m ) +inline constexpr MatrixMxN<Type>::MatrixMxN( const MatrixMxN& m ) : m_ ( m.m_ ) // The current number of rows of the matrix , n_ ( m.n_ ) // The current number of columns of the matrix , capacity_( m_*n_ ) // The maximum capacity of the matrix @@ -292,7 +292,7 @@ template< typename Type > // Data type of the matrix template< typename Other // Data type of the initialization array , size_t M // Number of rows of the initialization array , size_t N > // Number of columns of the initialization array -inline MatrixMxN<Type>::MatrixMxN( const Other (&rhs)[M][N] ) +inline constexpr MatrixMxN<Type>::MatrixMxN( const Other (&rhs)[M][N] ) : m_ ( M ) // The current number of rows of the matrix , n_ ( N ) // The current number of columns of the matrix , capacity_( M*N ) // The maximum capacity of the matrix -- GitLab