On Thu, Sep 10, 2009 at 10:04 AM, Nasos Iliopoulos <nasos_i@hotmail.com> wrote:
Wouldn't changing vectors' operator = allow that?
From:

BOOST_UBLAS_INLINE

vector &operator = (const vector &v) {

data () = v.data ();

return *this;

}


to

// pass by value for move semantics

BOOST_UBLAS_INLINE

vector &operator = (vector v) {

data().swap(v.data());

return *this;
}

I believe the above is called shallow copy and changes the current semantics of ublas (see http://www.osl.iu.edu/research/mtl/mtl4/doc/shallow_copy_problems.html) .  For example:
matrix<double> A(2,2);
//..... set A....

matrix<double> B = A;

Now they point at the same thing, not a copy/move.


Also, what about rvalues.  e.g.:

matrix<double> A = 2 * B;


And last, since this is using expression templates, the "data" vector may not exist, and will frequently not have the same type.


I don't know that much about this stuff, but my understanding is that rvalue refereces and move semantics allow a library to overload the rvalue assignment to do a this kind of pointer swapping.  But this stuff is probably very difficult to do.

-Jesse