From 7029ed6b8830937d3674064a3945642c99cb658f Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Wed, 29 Apr 2009 17:39:39 +0000 Subject: [PATCH] ok, this time cast should really work ; sorry for the noise --- Eigen/src/Core/DiagonalMatrix.h | 21 +++++++++++++++++++-- Eigen/src/Core/util/XprHelper.h | 8 ++++++-- 2 files changed, 25 insertions(+), 4 deletions(-) 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