To improve something, you have to measure it first.
That goes for your money as well.
GreaterThanZero.com


Page 6 of: Rvalue References Explained, by Thomas Becker   about me  

Move Semantics and Compiler Optimizations

Consider the following function definition:
X foo()
{
  X x;
  // perhaps do something to x
  return x;
}
Now suppose that as before, X is a class for which we have overloaded the copy constructor and copy assignment operator to implement move semantics. If you take the function definition above at face value, you may be tempted to say, wait a minute, there is a value copy happening here from x to the location of foo's return value. Let me make sure we're using move semantics instead:
X foo()
{
  X x;
  // perhaps do something to x
  return std::move(x); // making it worse!
}

Unfortunately, that would make things worse rather than better. Any modern compiler will apply return value optimization to the original function definition. In other words, rather than constructing an X locally and then copying it out, the compiler would construct the X object directly at the location of foo's return value. Rather obviously, that's even better than move semantics.

So as you can see, in order to really use rvalue references and move semantics in an optimal way, you need to fully understand and take into account today's compilers' "special effects" such as return value optimization and copy elision. Dave Abrahams has written an excellent series of articles on this subject on his blog. The details get pretty subtle, but hey, we chose C++ as our language of choice for a reason, right? We made our beds, so now let's lie in them.