Should I return an rvalue reference parameter by rvalue reference?

There’s no right answer, but returning by value is safer. I have read several questions on SO relating to returning rvalue references, and have come to the conclusion that this is bad practice. Returning a reference to a parameter foists a contract upon the caller that either The parameter cannot be a temporary (which is … Read more

How does std::move convert expressions to rvalues?

We start with the move function (which I cleaned up a little bit): template <typename T> typename remove_reference<T>::type&& move(T&& arg) { return static_cast<typename remove_reference<T>::type&&>(arg); } Let’s start with the easier part – that is, when the function is called with rvalue: Object a = std::move(Object()); // Object() is temporary, which is prvalue and our move … Read more

What is std::move(), and when should it be used and does it actually move anything?

1. “What is it?” While std::move() is technically a function – I would say it isn’t really a function. It’s sort of a converter between ways the compiler considers an expression’s value. 2. “What does it do?” The first thing to note is that std::move() doesn’t actually move anything. It changes an expression from being … Read more

What is std::move(), and when should it be used?

1. “What is it?” While std::move() is technically a function – I would say it isn’t really a function. It’s sort of a converter between ways the compiler considers an expression’s value. 2. “What does it do?” The first thing to note is that std::move() doesn’t actually move anything. It changes an expression from being … Read more