my previous fix was not very good

This commit is contained in:
Gael Guennebaud 2009-08-15 11:52:50 +02:00
parent 0da31a6e1d
commit 7b60713e87
2 changed files with 22 additions and 11 deletions

View File

@ -149,15 +149,31 @@ class ScaledProduct;
// define all overloads defined in MatrixBase. Furthermore, Using // define all overloads defined in MatrixBase. Furthermore, Using
// "using Base::operator*" would not work with MSVC. // "using Base::operator*" would not work with MSVC.
// //
// Also note that here we accept any type which can be converted to Derived::Scalar. // Also note that here we accept any compatible scalar types
template<typename Derived,typename Lhs,typename Rhs,typename Scalar> template<typename Derived,typename Lhs,typename Rhs>
const ScaledProduct<Derived> operator*(const ProductBase<Derived,Lhs,Rhs>& prod, Scalar x) const ScaledProduct<Derived>
operator*(const ProductBase<Derived,Lhs,Rhs>& prod, typename Derived::Scalar x)
{ return ScaledProduct<Derived>(prod.derived(), x); } { return ScaledProduct<Derived>(prod.derived(), x); }
template<typename Derived,typename Lhs,typename Rhs,typename Scalar> template<typename Derived,typename Lhs,typename Rhs>
const ScaledProduct<Derived> operator*(Scalar x,const ProductBase<Derived,Lhs,Rhs>& prod) typename ei_enable_if<!ei_is_same_type<typename Derived::Scalar,typename Derived::RealScalar>::ret,
const ScaledProduct<Derived> >::type
operator*(const ProductBase<Derived,Lhs,Rhs>& prod, typename Derived::RealScalar x)
{ return ScaledProduct<Derived>(prod.derived(), x); } { return ScaledProduct<Derived>(prod.derived(), x); }
template<typename Derived,typename Lhs,typename Rhs>
const ScaledProduct<Derived>
operator*(typename Derived::Scalar x,const ProductBase<Derived,Lhs,Rhs>& prod)
{ return ScaledProduct<Derived>(prod.derived(), x); }
template<typename Derived,typename Lhs,typename Rhs>
typename ei_enable_if<!ei_is_same_type<typename Derived::Scalar,typename Derived::RealScalar>::ret,
const ScaledProduct<Derived> >::type
operator*(typename Derived::RealScalar x,const ProductBase<Derived,Lhs,Rhs>& prod)
{ return ScaledProduct<Derived>(prod.derived(), x); }
template<typename NestedProduct> template<typename NestedProduct>
struct ei_traits<ScaledProduct<NestedProduct> > struct ei_traits<ScaledProduct<NestedProduct> >
: ei_traits<ProductBase<ScaledProduct<NestedProduct>, : ei_traits<ProductBase<ScaledProduct<NestedProduct>,

View File

@ -155,12 +155,7 @@ template<int Y, int InfX, int SupX>
class ei_meta_sqrt<Y, InfX, SupX, true> { public: enum { ret = (SupX*SupX <= Y) ? SupX : InfX }; }; class ei_meta_sqrt<Y, InfX, SupX, true> { public: enum { ret = (SupX*SupX <= Y) ? SupX : InfX }; };
/** \internal determines whether the product of two numeric types is allowed and what the return type is */ /** \internal determines whether the product of two numeric types is allowed and what the return type is */
template<typename T, typename U> struct ei_scalar_product_traits template<typename T, typename U> struct ei_scalar_product_traits;
{
// dummy general case where T and U aren't compatible -- not allowed anyway but we catch it elsewhere
//enum { Cost = NumTraits<T>::MulCost };
typedef T ReturnType;
};
template<typename T> struct ei_scalar_product_traits<T,T> template<typename T> struct ei_scalar_product_traits<T,T>
{ {