
BTW the swap member function offers a C++03 way to "move assign" [from] an rvalue:
std::vector<int> generate_some_data(void); std::vector<int> my_data; // Move the result into my_data: generate_some_data().swap(my_data);
Giovanni Piero Deretta wrote:
I guess this is a common idiom, I use it a lot.
OTOH if my_data::operator=() used pass by value (which in the case of standard containers is, unfortunately, not true), the member swap wouldn't be necessary.
In practice this means that, for your own classes, or you implement the 'smart' operator= or you need the member swap (to swap out of temporaries). You do not need both.
When having a by-value argument for operator=, a compiler is /allowed/ to do copy elision, but it's not /required/ to do do. So I'd recommend you to just keep swapping your rvalues (using member swap) if you already do so anyway :-) Kind regards, Niels