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 comment

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