Boost logo

Ublas :

From: Michael Stevens (mail_at_[hidden])
Date: 2005-02-16 13:56:13

Hi Glen,

On Wednesday 16 February 2005 18:08, glen stark wrote:
> am I correct that the scalar_vector does not support the assignement
> operator for value types?
> in other words, it seems I can't do the following:
> scalar_vector<double> someScalarVector(3,2.0);
> someScalarVector = 3;
> Was this a design decision? May I ask the reasoning behind it?
> I would think the above usage would be quite useful.

I would be guessing but I would guess the design is trying to be consistent
and simple. It is consistent because zero_vector, identity_vector and
scalar_vector have common interface structure. It is simple in that it does
not overload additional operators for special purposes.

> Is there another method in mind for the above behavior?
> The only thing I can see from the
> documenation woudl be to create a temporary scalar_vector and assign
> this...

I think this is a good way to go. If you like the = syntax you can define
        operator= (scalar_vector<double> v, double s)
                v = scalar_vector<double> (v.size(), s);
A good compiler should turn this into efficient code.

Personally I would use a normal function, I had to look several times at you
code example before I could figure out what it was supposed to do!

> Is there a reason why the following addition would be a bad idea?
> scalar_vector &assign_temporary (scalar_vector &v) {
> swap (v);
> return *this;
> }

I'm a bit confused here. This member function is already in scalar_vector, or
is it missing or non functional in some version of uBLAS?