What does std::move(x) actually do in C++?
Correct answer
C. Casts x to an rvalue reference so it can be moved from
13 views
C. Casts x to an rvalue reference so it can be moved from
13 views
std::move is only a static_cast to an rvalue reference; it performs no data transfer by itself, and the actual work happens in a move constructor or move assignment operator that takes the rvalue. If no such overload exists, the const-bound copy constructor is selected and a copy silently occurs. After a move, the source remains valid but unspecified, so it may be assigned or destroyed but should not be read for its old value.
Asked in: NTS, PPSC IT, Campus Interviews
Not sure why the answer is C? Ask here and get an explanation.