diff --git a/Eigen/src/Core/DiagonalMatrix.h b/Eigen/src/Core/DiagonalMatrix.h index a95a45eb3..57f92a968 100644 --- a/Eigen/src/Core/DiagonalMatrix.h +++ b/Eigen/src/Core/DiagonalMatrix.h @@ -70,6 +70,22 @@ class DiagonalMatrixBase : ei_no_assignment_operator, construct_from_expression ::run(derived(),other.derived()); } + + template + struct cast_selector { + typedef const DiagonalMatrixWrapper, _CoeffsVectorType> > > return_type; + inline static return_type run(const DiagonalMatrixBase& d) { + return d.m_coeffs.template cast().nestByValue().asDiagonal(); + } + }; + + template + struct cast_selector { + typedef const Derived& return_type; + inline static return_type run(const DiagonalMatrixBase& d) { + return d.derived(); + } + }; public: @@ -80,9 +96,10 @@ class DiagonalMatrixBase : ei_no_assignment_operator, } template - inline DiagonalMatrixWrapper, _CoeffsVectorType> > > cast() const + inline typename cast_selector::return_type + cast() const { - return m_coeffs.template cast().nestByValue().asDiagonal(); + return cast_selector::run(*this); } /** Assignment operator. diff --git a/Eigen/src/Core/util/XprHelper.h b/Eigen/src/Core/util/XprHelper.h index 857722b79..6ffe14762 100644 --- a/Eigen/src/Core/util/XprHelper.h +++ b/Eigen/src/Core/util/XprHelper.h @@ -242,9 +242,13 @@ template struct HNormalizedReturnType { NestByValue > Type; }; -template struct ei_cast_return_type +template struct ei_cast_return_type { - typedef typename ei_meta_if::ret,const CurrentType&,NewType>::ret type; + typedef typename XprType::Scalar CurrentScalarType; + typedef typename ei_cleantype::type _CastType; + typedef typename _CastType::Scalar NewScalarType; + typedef typename ei_meta_if::ret, + const XprType&,CastType>::ret type; }; #endif // EIGEN_XPRHELPER_H