From 3b727ef939f5888a8931b231edcf31c00de8bf69 Mon Sep 17 00:00:00 2001 From: Benoit Jacob Date: Sun, 9 Sep 2007 09:03:42 +0000 Subject: some cleanup --- doc/tutorial.cpp | 1 - src/MatrixBase.h | 22 +++++++++++----------- src/MatrixXpr.h | 2 ++ 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/doc/tutorial.cpp b/doc/tutorial.cpp index 60d204ce6..967f0a544 100644 --- a/doc/tutorial.cpp +++ b/doc/tutorial.cpp @@ -25,7 +25,6 @@ int main(int, char **) m2.block(2,3,2,3) = m - m; cout << "Now the 4x4 matrix m2 is:" << endl << m2 << endl; - // here we don't need to use .xpr() because we only need read access. cout << "The central 2x2 block of m2 is:" << endl << m2.block(1,2,1,2) << endl; cout << "Row 0 of m2, written as a column vector, is:" << endl << m2.row(0) << endl; cout << "Column 1 of m2 is:" << endl << m2.col(1) << endl; diff --git a/src/MatrixBase.h b/src/MatrixBase.h index d49ce8c21..5859a14cc 100644 --- a/src/MatrixBase.h +++ b/src/MatrixBase.h @@ -247,6 +247,11 @@ template class MatrixAlias m_aliased.xpr() = m_tmp; } + Ref ref() + { + return Ref(*this); + } + Xpr xpr() { return Xpr(ref()); @@ -270,11 +275,6 @@ template class MatrixAlias return m_tmp.write(row, col); } - Ref ref() - { - return Ref(*this); - } - MatrixXpr > row(int i) { return xpr().row(i); }; MatrixXpr > col(int i) { return xpr().col(i); }; MatrixXpr > minor(int row, int col) { return xpr().minor(row, col); }; @@ -285,21 +285,21 @@ template class MatrixAlias } template - void operator=(const MatrixXpr &xpr) + void operator=(const MatrixXpr &other) { - ref().xpr() = xpr; + xpr() = other; } template - void operator+=(const MatrixXpr &xpr) + void operator+=(const MatrixXpr &other) { - ref().xpr() += xpr; + xpr() += other; } template - void operator-=(const MatrixXpr &xpr) + void operator-=(const MatrixXpr &other) { - ref().xpr() -= xpr; + xpr() -= other; } protected: diff --git a/src/MatrixXpr.h b/src/MatrixXpr.h index a42f84af6..fe890d16c 100644 --- a/src/MatrixXpr.h +++ b/src/MatrixXpr.h @@ -70,6 +70,8 @@ template class MatrixXpr return *this; } + //special case of the above template operator=. Strangely, g++ 4.1 failed to use + //that template when OtherContent == Content MatrixXpr& operator=(const MatrixXpr& other) { assert(rows() == other.rows() && cols() == other.cols()); -- cgit v1.2.3