From 75b7d98665dd144c44d7a113c6613f5f998be626 Mon Sep 17 00:00:00 2001 From: Benoit Jacob Date: Wed, 22 Dec 2010 17:45:37 -0500 Subject: bug #54 - really fix const correctness except in Sparse --- Eigen/src/Core/Diagonal.h | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) (limited to 'Eigen/src/Core/Diagonal.h') diff --git a/Eigen/src/Core/Diagonal.h b/Eigen/src/Core/Diagonal.h index 158bc6df7..30818f6d1 100644 --- a/Eigen/src/Core/Diagonal.h +++ b/Eigen/src/Core/Diagonal.h @@ -64,7 +64,8 @@ struct traits > MatrixType::MaxColsAtCompileTime) : (EIGEN_SIZE_MIN_PREFER_FIXED(MatrixType::MaxRowsAtCompileTime, MatrixType::MaxColsAtCompileTime) - AbsDiagIndex), MaxColsAtCompileTime = 1, - Flags = (unsigned int)_MatrixTypeNested::Flags & (HereditaryBits | LinearAccessBit | LvalueBit | DirectAccessBit) & ~RowMajorBit, + MaskLvalueBit = is_lvalue::value ? LvalueBit : 0, + Flags = (unsigned int)_MatrixTypeNested::Flags & (HereditaryBits | LinearAccessBit | MaskLvalueBit | DirectAccessBit) & ~RowMajorBit, CoeffReadCost = _MatrixTypeNested::CoeffReadCost, MatrixTypeOuterStride = outer_stride_at_compile_time::ret, InnerStrideAtCompileTime = MatrixTypeOuterStride == Dynamic ? Dynamic : MatrixTypeOuterStride+1, @@ -105,6 +106,11 @@ template class Diagonal return m_matrix.const_cast_derived().coeffRef(row+rowOffset(), row+colOffset()); } + inline const Scalar& coeffRef(Index row, Index) const + { + return m_matrix.const_cast_derived().coeffRef(row+rowOffset(), row+colOffset()); + } + inline CoeffReturnType coeff(Index row, Index) const { return m_matrix.coeff(row+rowOffset(), row+colOffset()); @@ -115,6 +121,11 @@ template class Diagonal return m_matrix.const_cast_derived().coeffRef(index+rowOffset(), index+colOffset()); } + inline const Scalar& coeffRef(Index index) const + { + return m_matrix.const_cast_derived().coeffRef(index+rowOffset(), index+colOffset()); + } + inline CoeffReturnType coeff(Index index) const { return m_matrix.coeff(index+rowOffset(), index+colOffset()); @@ -143,18 +154,18 @@ template class Diagonal * * \sa class Diagonal */ template -inline Diagonal +inline typename MatrixBase::DiagonalReturnType MatrixBase::diagonal() { - return Diagonal(derived()); + return derived(); } /** This is the const version of diagonal(). */ template -inline const Diagonal +inline const typename MatrixBase::ConstDiagonalReturnType MatrixBase::diagonal() const { - return Diagonal(derived()); + return derived(); } /** \returns an expression of the \a DiagIndex-th sub or super diagonal of the matrix \c *this @@ -169,18 +180,18 @@ MatrixBase::diagonal() const * * \sa MatrixBase::diagonal(), class Diagonal */ template -inline Diagonal +inline typename MatrixBase::template DiagonalIndexReturnType::Type MatrixBase::diagonal(Index index) { - return Diagonal(derived(), index); + return typename DiagonalIndexReturnType::Type(derived(), index); } /** This is the const version of diagonal(Index). */ template -inline const Diagonal +inline typename MatrixBase::template ConstDiagonalIndexReturnType::Type MatrixBase::diagonal(Index index) const { - return Diagonal(derived(), index); + return typename ConstDiagonalIndexReturnType::Type(derived(), index); } /** \returns an expression of the \a DiagIndex-th sub or super diagonal of the matrix \c *this @@ -195,20 +206,20 @@ MatrixBase::diagonal(Index index) const * * \sa MatrixBase::diagonal(), class Diagonal */ template -template -inline Diagonal +template +inline typename MatrixBase::template DiagonalIndexReturnType::Type MatrixBase::diagonal() { - return Diagonal(derived()); + return derived(); } /** This is the const version of diagonal(). */ template -template -inline const Diagonal +template +inline typename MatrixBase::template ConstDiagonalIndexReturnType::Type MatrixBase::diagonal() const { - return Diagonal(derived()); + return derived(); } #endif // EIGEN_DIAGONAL_H -- cgit v1.2.3