Boost logo

Ublas :

From: Johan Compen (johanc_at_[hidden])
Date: 2008-04-29 07:26:18


On Mon, Apr 28, 2008 at 5:41 PM, Andreas Klöckner
<lists_at_[hidden]> wrote:
>
> On Montag 28 April 2008, Johan Compen wrote:
> > Hi,
> >
> > I'm using the vector and matrix classes in Boost to convert some
> > Matlab code to C++. I'm having troubles with this code:
> >
> > typedef boost::numeric::ublas::vector<double> Vector_t;
> > Vector_t a(3);
> > a(0) = 0; a(1)=1; a(2)=2;
> >
> > Vector_t b = a * 0.5; //works
> > Vector_t c = a + 0.5; //compiler error
> >
> > error C2678: binary '+' : no operator found which takes a left-hand
> > operand of type 'Vector_t' (or there is no acceptable conversion)
> >
> > How can I solve this? How can I add a constant value to each element
> > in a vector?
>
> c = a + scalar_vector<double>(a.size(), 0.5);

Ok this works, but why isn't there an operator+ that adds a constant
value to each element in a vector?
It seems inconsistent to me that this works
Vector_t b = a * 0.5;
but this doesn't
Vector_t c = a + 0.5;

Johan.