2012-04-11

How rvalue references and moving in c++ behave

I had enough of decyphering the cryptic standard of c++11 today and decided I'll just write a bunch of code to tell me how it *really* works.


Before going forward, you should look at the code or get the code and/or see the output.

So, the above code is pretty self-explanatory. Now here are the findings:

If you return by value, a move constructor will be called if it is defined.

If you return by rvalue reference (refref), a move constructor will also be called, but don't do that, because you cannot safely return objects constructed in functions from functions as references.

Basically, that's it :)