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/Transpose.h | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) (limited to 'Eigen/src/Core/Transpose.h') diff --git a/Eigen/src/Core/Transpose.h b/Eigen/src/Core/Transpose.h index 394b375ab..1c9403eba 100644 --- a/Eigen/src/Core/Transpose.h +++ b/Eigen/src/Core/Transpose.h @@ -46,7 +46,7 @@ struct traits > : traits { typedef typename MatrixType::Scalar Scalar; typedef typename nested::type MatrixTypeNested; - typedef typename remove_reference::type _MatrixTypeNested; + typedef typename remove_reference::type MatrixTypeNestedPlain; typedef typename traits::StorageKind StorageKind; typedef typename traits::XprKind XprKind; enum { @@ -54,8 +54,11 @@ struct traits > : traits ColsAtCompileTime = MatrixType::RowsAtCompileTime, MaxRowsAtCompileTime = MatrixType::MaxColsAtCompileTime, MaxColsAtCompileTime = MatrixType::MaxRowsAtCompileTime, - Flags = int(_MatrixTypeNested::Flags & ~NestByRefBit) ^ RowMajorBit, - CoeffReadCost = _MatrixTypeNested::CoeffReadCost, + FlagsLvalueBit = is_lvalue::value ? LvalueBit : 0, + Flags0 = MatrixTypeNestedPlain::Flags & ~(LvalueBit | NestByRefBit), + Flags1 = Flags0 | FlagsLvalueBit, + Flags = Flags1 ^ RowMajorBit, + CoeffReadCost = MatrixTypeNestedPlain::CoeffReadCost, InnerStrideAtCompileTime = inner_stride_at_compile_time::ret, OuterStrideAtCompileTime = outer_stride_at_compile_time::ret }; @@ -122,12 +125,24 @@ template class TransposeImpl inline Scalar& coeffRef(Index row, Index col) { - return const_cast_derived().nestedExpression().coeffRef(col, row); + EIGEN_STATIC_ASSERT_LVALUE(MatrixType) + return derived().nestedExpression().const_cast_derived().coeffRef(col, row); } inline Scalar& coeffRef(Index index) { - return const_cast_derived().nestedExpression().coeffRef(index); + EIGEN_STATIC_ASSERT_LVALUE(MatrixType) + return derived().nestedExpression().const_cast_derived().coeffRef(index); + } + + inline const Scalar& coeffRef(Index row, Index col) const + { + return derived().nestedExpression().coeffRef(col, row); + } + + inline const Scalar& coeffRef(Index index) const + { + return derived().nestedExpression().coeffRef(index); } inline const CoeffReturnType coeff(Index row, Index col) const @@ -149,7 +164,7 @@ template class TransposeImpl template inline void writePacket(Index row, Index col, const PacketScalar& x) { - const_cast_derived().nestedExpression().template writePacket(col, row, x); + derived().nestedExpression().const_cast_derived().template writePacket(col, row, x); } template @@ -161,7 +176,7 @@ template class TransposeImpl template inline void writePacket(Index index, const PacketScalar& x) { - const_cast_derived().nestedExpression().template writePacket(index, x); + derived().nestedExpression().const_cast_derived().template writePacket(index, x); } }; @@ -197,7 +212,7 @@ DenseBase::transpose() * * \sa transposeInPlace(), adjoint() */ template -inline const Transpose +inline const typename DenseBase::ConstTransposeReturnType DenseBase::transpose() const { return derived(); @@ -226,7 +241,8 @@ template inline const typename MatrixBase::AdjointReturnType MatrixBase::adjoint() const { - return this->transpose(); + return this->transpose(); // in the complex case, the .conjugate() is be implicit here + // due to implicit conversion to return type } /*************************************************************************** -- cgit v1.2.3