fix compilation of code using e.g. Transpose<const Foo>::data() non-const-qualified. Same problem existed for coeffRef() and also in MapBase.h.

This commit is contained in:
Benoit Jacob 2010-12-30 07:47:51 -05:00
parent 26c2afd55a
commit 13867c15cc
2 changed files with 20 additions and 7 deletions

View File

@ -201,15 +201,21 @@ template<typename Derived> class MapBase<Derived, WriteAccessors>
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<Derived>::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()];

View File

@ -120,16 +120,23 @@ template<typename MatrixType> class TransposeImpl<MatrixType,Dense>
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<MatrixType>::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);