What is std::move and is it a cast?
Short answer
std::move doesn't move anything—it's a cast that unconditionally converts its argument to an rvalue reference (T&&), signaling that the object may be 'moved from'. This lets overload resolution pick move constructors/assignment.
Advertisement
AModel answer
std::move doesn't move anything—it's a cast that unconditionally converts its argument to an rvalue reference (T&&), signaling that the object may be 'moved from'. This lets overload resolution pick move constructors/assignment. The actual moving is done by those move operations, not by std::move itself.
std::string a = "hi";
std::string b = std::move(a); // a is now moved-fromReal-world example
std::move on a large temporary vector enables a cheap move instead of a deep copy into a container.
Likely follow-ups
- Does std::move perform the move? | What does it cast to?
Related topics