Re: [eigen] static_cast versus constructor

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]




On 8/27/12 5:44 AM, Gael Guennebaud wrote:
Hi,

our default implementation for the .cast<NewType>() function makes use
of static_cast as in Eigen/src/Core/MathFunctions.h:395:

template<typename OldType, typename NewType>
struct cast_impl
{
   static inline NewType run(const OldType& x)
   {
     return static_cast<NewType>(x);
   }
};

Would not it be better to use constructors:

template<typename OldType, typename NewType>
struct cast_impl
{
   static inline NewType run(const OldType& x)
   {
     return NewType(x);
   }
};

which is more likely to be accepted by custom scalar types. Does
anyone see any drawbacks of such a change?

If the second impl with the ctor works, so will the
first.  The full set of rules for static_cast are:

http://en.cppreference.com/w/cpp/language/static_cast

- Bob




Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/