If you’re using a C++0x-compatible compiler and standard library, you get better performance from the first example without doing anything. The return value of get_vector(_n, _m)
is a temporary, and the move constructor for std::vector
(a constructor taking an rvalue reference) will automatically be called with no further work on your part.
In general, non-library writers won’t need to use rvalue references directly; you’ll just reap a decent chunk of the benefits automatically.