aboutsummaryrefslogtreecommitdiffhomepage
path: root/Eigen/src
diff options
context:
space:
mode:
authorGravatar Gael Guennebaud <g.gael@free.fr>2009-04-29 17:39:39 +0000
committerGravatar Gael Guennebaud <g.gael@free.fr>2009-04-29 17:39:39 +0000
commit7029ed6b8830937d3674064a3945642c99cb658f (patch)
tree55337799e181f070df0d83a60802a21f645f9ba0 /Eigen/src
parent428a12902a426ab90bb8888a4a9021781884b337 (diff)
ok, this time cast should really work ; sorry for the noise
Diffstat (limited to 'Eigen/src')
-rw-r--r--Eigen/src/Core/DiagonalMatrix.h21
-rw-r--r--Eigen/src/Core/util/XprHelper.h8
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<OtherDerived,OtherDerived::IsVectorAtCompileTime,(OtherDerived::Flags&Diagonal)==Diagonal>
::run(derived(),other.derived());
}
+
+ template<typename NewType,int dummy=0>
+ struct cast_selector {
+ typedef const DiagonalMatrixWrapper<NestByValue<CwiseUnaryOp<ei_scalar_cast_op<Scalar, NewType>, _CoeffsVectorType> > > return_type;
+ inline static return_type run(const DiagonalMatrixBase& d) {
+ return d.m_coeffs.template cast<NewType>().nestByValue().asDiagonal();
+ }
+ };
+
+ template<int dummy>
+ struct cast_selector<Scalar,dummy> {
+ 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<typename NewType>
- inline DiagonalMatrixWrapper<NestByValue<CwiseUnaryOp<ei_scalar_cast_op<Scalar, NewType>, _CoeffsVectorType> > > cast() const
+ inline typename cast_selector<NewType,0>::return_type
+ cast() const
{
- return m_coeffs.template cast<NewType>().nestByValue().asDiagonal();
+ return cast_selector<NewType,0>::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<typename ExpressionType> struct HNormalizedReturnType {
NestByValue<StartMinusOne> > Type;
};
-template<typename CurrentType, typename NewType> struct ei_cast_return_type
+template<typename XprType, typename CastType> struct ei_cast_return_type
{
- typedef typename ei_meta_if<ei_is_same_type<CurrentType,NewType>::ret,const CurrentType&,NewType>::ret type;
+ typedef typename XprType::Scalar CurrentScalarType;
+ typedef typename ei_cleantype<CastType>::type _CastType;
+ typedef typename _CastType::Scalar NewScalarType;
+ typedef typename ei_meta_if<ei_is_same_type<CurrentScalarType,NewScalarType>::ret,
+ const XprType&,CastType>::ret type;
};
#endif // EIGEN_XPRHELPER_H