From 13867c15cca7716ff36c2ee2c9b37ebe2721cd9a Mon Sep 17 00:00:00 2001 From: Benoit Jacob Date: Thu, 30 Dec 2010 07:47:51 -0500 Subject: [PATCH] fix compilation of code using e.g. Transpose::data() non-const-qualified. Same problem existed for coeffRef() and also in MapBase.h. --- Eigen/src/Core/MapBase.h | 14 ++++++++++---- Eigen/src/Core/Transpose.h | 13 ++++++++++--- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/Eigen/src/Core/MapBase.h b/Eigen/src/Core/MapBase.h index d8ecdf2f4..826e4049d 100644 --- a/Eigen/src/Core/MapBase.h +++ b/Eigen/src/Core/MapBase.h @@ -201,15 +201,21 @@ template class MapBase using Base::rowStride; using Base::colStride; - inline const Scalar* data() const { return this->m_data; } - inline Scalar* data() { return this->m_data; } // no const-cast here so non-const-correct code will give a compile error + typedef typename internal::conditional< + internal::is_lvalue::value, + Scalar, + const Scalar + >::type ScalarWithConstIfNotLvalue; - inline Scalar& coeffRef(Index row, Index col) + inline const Scalar* data() const { return this->m_data; } + inline ScalarWithConstIfNotLvalue* data() { return this->m_data; } // no const-cast here so non-const-correct code will give a compile error + + inline ScalarWithConstIfNotLvalue& coeffRef(Index row, Index col) { return this->m_data[col * colStride() + row * rowStride()]; } - inline Scalar& coeffRef(Index index) + inline ScalarWithConstIfNotLvalue& coeffRef(Index index) { EIGEN_STATIC_ASSERT_LINEAR_ACCESS(Derived) return this->m_data[index * innerStride()]; diff --git a/Eigen/src/Core/Transpose.h b/Eigen/src/Core/Transpose.h index 1c9403eba..a5687790f 100644 --- a/Eigen/src/Core/Transpose.h +++ b/Eigen/src/Core/Transpose.h @@ -120,16 +120,23 @@ template class TransposeImpl inline Index innerStride() const { return derived().nestedExpression().innerStride(); } inline Index outerStride() const { return derived().nestedExpression().outerStride(); } - inline Scalar* data() { return derived().nestedExpression().data(); } + + typedef typename internal::conditional< + internal::is_lvalue::value, + Scalar, + const Scalar + >::type ScalarWithConstIfNotLvalue; + + inline ScalarWithConstIfNotLvalue* data() { return derived().nestedExpression().data(); } inline const Scalar* data() const { return derived().nestedExpression().data(); } - inline Scalar& coeffRef(Index row, Index col) + inline ScalarWithConstIfNotLvalue& coeffRef(Index row, Index col) { EIGEN_STATIC_ASSERT_LVALUE(MatrixType) return derived().nestedExpression().const_cast_derived().coeffRef(col, row); } - inline Scalar& coeffRef(Index index) + inline ScalarWithConstIfNotLvalue& coeffRef(Index index) { EIGEN_STATIC_ASSERT_LVALUE(MatrixType) return derived().nestedExpression().const_cast_derived().coeffRef(index);