J
Jonathan Lee
Hi all,
I was wondering if there is a good way to detect an assignment from
an anonymous variable, so that the assignment might be accomplished by
a move, instead of a copy. For example:
MatrixClass x, y, z
// stuff happens to x, y, and z
// ...
z = x + y;
Suppose MatrixClass keeps a pointer to its data, which will be deleted
on destruction. Rather than copy (x + y) to z, it would be cheaper to
simply exchange the pointers inside the classes and allow the old z
data be deleted when (x + y) is destroyed.
Can such a thing be done automatically? Or would I have to use
something like
swap(z, x + y);
instead?
--Jonathan
I was wondering if there is a good way to detect an assignment from
an anonymous variable, so that the assignment might be accomplished by
a move, instead of a copy. For example:
MatrixClass x, y, z
// stuff happens to x, y, and z
// ...
z = x + y;
Suppose MatrixClass keeps a pointer to its data, which will be deleted
on destruction. Rather than copy (x + y) to z, it would be cheaper to
simply exchange the pointers inside the classes and allow the old z
data be deleted when (x + y) is destroyed.
Can such a thing be done automatically? Or would I have to use
something like
swap(z, x + y);
instead?
--Jonathan