Re: [eigen] Overloading componentwise binary operators for vectors

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


On Fri, 2 Oct 2015, Cedric Doucet wrote:

I try to overload binary operators for a VectorWrapper but I don't manage to do it.
My wrapper looks like this :

========================================================
template<typename ScalarType>
class Vector
{
public:
typedef Eigen::Matrix<ScalarType,Eigen::Dynamic,1> VectorType;

private:
VectorType wrapped_;
};
========================================================

Don't worry about names, data structure, etc, or the necessity of wrapping such a thing: it is just an example to illustrate my problem.
So, I would like to overload binary operators for Vector class, for example the sum of two vectors.
It seems that the classical version:

========================================================
template<typename ScalarType>
Vector<ScalarType> operator+(Vector<ScalarType> const & lhs, Vector<ScalarType> const & rhs)
{ return lhs.wrapped_ + right.wrapped_; }
========================================================

does not work. I guess it is because an expression template is returned by operator + in Eigen.

Er, clearly you left some code out, because Vector doesn't have any constructor and you construct one from an int in the test (and expect to construct one from something convertible to a VectorType in operator+). You also failed to mention what "doesn't work" means.

--
Marc Glisse



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