std::move doesn’t do move

std::move doesn’t really move anything. All move does is accept either an lvalue or rvalue argument, and return it as an rvalue without triggering a copy construction[1]:

template <class T> 
typename remove_reference<T>::type&& 
move(T&& a) {
    return a;

Some information in this talk by Scott Meyers.

[1] Move semantics.
[2] C++ Rvalue References Explained.
[3] Lvalues and Rvalues.
[4] Universal References in C++11.

This entry was posted in C++. Bookmark the permalink.

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.