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