Add smart cast functions and ctor with scalar conversion (explicit)

to all classes of the Geometry module. By smart I mean that if current
type == new type, then it returns a const reference to *this => zero overhead
This commit is contained in:
Gael Guennebaud
2008-10-25 22:38:22 +00:00
parent 568a7e8eba
commit e5b8a59cfa
9 changed files with 361 additions and 224 deletions

View File

@@ -128,6 +128,20 @@ public:
return *this;
}
/** \returns \c *this with scalar type casted to \a NewScalarType
*
* Note that if \a NewScalarType is equal to the current scalar type of \c *this
* then this function smartly returns a const reference to \c *this.
*/
template<typename NewScalarType>
typename ei_cast_return_type<Scaling,Scaling<NewScalarType,Dim> >::type cast() const
{ return typename ei_cast_return_type<Scaling,Scaling<NewScalarType,Dim> >::type(*this); }
/** Copy constructor with scalar type conversion */
template<typename OtherScalarType>
explicit Scaling(const Scaling<OtherScalarType,Dim>& other)
{ m_coeffs = other.coeffs().template cast<OtherScalarType>(); }
};
/** \addtogroup GeometryModule */