diff --git a/src/internal/Block.h b/src/internal/Block.h index ca2c67465..0664abb58 100644 --- a/src/internal/Block.h +++ b/src/internal/Block.h @@ -75,10 +75,10 @@ template class EiBlock }; template -EiBlock > +EiBlock EiObject::block(int startRow, int endRow, int startCol, int endCol) { - return EiBlock(ref(), startRow, endRow, startCol, endCol); + return EiBlock(static_cast(this)->ref(), startRow, endRow, startCol, endCol); } #endif // EI_BLOCK_H diff --git a/src/internal/Eval.h b/src/internal/Eval.h index 2b79866ed..2d792d822 100644 --- a/src/internal/Eval.h +++ b/src/internal/Eval.h @@ -28,15 +28,14 @@ template class EiEval : public EiMatrix< typename Expression::Scalar, - Expression::Derived::RowsAtCompileTime, - Expression::Derived::ColsAtCompileTime > + Expression::RowsAtCompileTime, + Expression::ColsAtCompileTime > { public: typedef typename Expression::Scalar Scalar; - typedef typename Expression::Derived Derived; - typedef EiMatrix< Scalar, Derived::RowsAtCompileTime, Derived::ColsAtCompileTime> MatrixType; + typedef EiMatrix< Scalar, Expression::RowsAtCompileTime, Expression::ColsAtCompileTime> MatrixType; typedef Expression Base; - friend class EiObject; + friend class EiObject; EI_INHERIT_ASSIGNMENT_OPERATORS(EiEval) @@ -44,9 +43,9 @@ template class EiEval }; template -EiEval > EiObject::eval() const +EiEval EiObject::eval() const { - return EiEval >(*this); + return EiEval(*static_cast(this)); } #endif // EI_EVAL_H diff --git a/src/internal/Minor.h b/src/internal/Minor.h index 77fa4b9c8..abd8fe03c 100644 --- a/src/internal/Minor.h +++ b/src/internal/Minor.h @@ -71,10 +71,10 @@ template class EiMinor }; template -EiMinor > +EiMinor EiObject::minor(int row, int col) { - return EiMinor(ref(), row, col); + return EiMinor(static_cast(this)->ref(), row, col); } #endif // EI_MINOR_H diff --git a/src/internal/Object.h b/src/internal/Object.h index fde835001..fefa15897 100644 --- a/src/internal/Object.h +++ b/src/internal/Object.h @@ -28,14 +28,21 @@ #include "Util.h" -template class EiObject +template class EiObject { - static const int RowsAtCompileTime = _Derived::RowsAtCompileTime, - ColsAtCompileTime = _Derived::ColsAtCompileTime; + static const int RowsAtCompileTime = Derived::RowsAtCompileTime, + ColsAtCompileTime = Derived::ColsAtCompileTime; + + template + void _copy_helper(const EiObject& other) + { + for(int i = 0; i < rows(); i++) + for(int j = 0; j < cols(); j++) + write(i, j) = other.read(i, j); + } + public: - typedef typename EiForwardDecl<_Derived>::Ref Ref; - typedef _Scalar Scalar; - typedef _Derived Derived; + typedef typename EiForwardDecl::Ref Ref; int rows() const { return static_cast(this)->_rows(); } int cols() const { return static_cast(this)->_cols(); } @@ -61,9 +68,7 @@ template class EiObject Derived& operator=(const EiObject& other) { assert(rows() == other.rows() && cols() == other.cols()); - for(int i = 0; i < rows(); i++) - for(int j = 0; j < cols(); j++) - write(i, j) = other.read(i, j); + _copy_helper(other); return *static_cast(this); } @@ -72,17 +77,14 @@ template class EiObject Derived& operator=(const EiObject& other) { assert(rows() == other.rows() && cols() == other.cols()); - for(int i = 0; i < rows(); i++) - for(int j = 0; j < cols(); j++) - write(i, j) = other.read(i, j); + _copy_helper(other); return *static_cast(this); } - EiRow row(int i); - EiColumn col(int i); - EiMinor minor(int row, int col); - EiBlock - block(int startRow, int endRow, int startCol= 0, int endCol = 0); + EiRow row(int i); + EiColumn col(int i); + EiMinor minor(int row, int col); + EiBlock block(int startRow, int endRow, int startCol= 0, int endCol = 0); template Derived& operator+=(const EiObject& other); @@ -111,7 +113,7 @@ template class EiObject Scalar& operator()(int row, int col = 0) { return write(row, col); } - EiEval eval() const; + EiEval eval() const; }; template diff --git a/src/internal/RowAndCol.h b/src/internal/RowAndCol.h index 0bfc361b0..00079c81f 100644 --- a/src/internal/RowAndCol.h +++ b/src/internal/RowAndCol.h @@ -128,17 +128,17 @@ template class EiColumn }; template -EiRow > +EiRow EiObject::row(int i) { - return EiRow(ref(), i); + return EiRow(static_cast(this)->ref(), i); } template -EiColumn > +EiColumn EiObject::col(int i) { - return EiColumn(ref(), i); + return EiColumn(static_cast(this)->ref(), i); } #endif // EI_ROWANDCOL_H