- What is it?
- What does it do?
- When should it be used?
Good links are appreciated.
- In C++11, in addition to copy constructors, objects can have move constructors.
(And in addition to copy assignment operators, they have move assignment operators.)
- The move constructor is used instead of the copy constructor, if the object has type “rvalue-reference” (
std::move()is a cast that produces an rvalue-reference to an object, to enable moving from it.
It’s a new C++ way to avoid copies. For example, using a move constructor, a
std::vector could just copy its internal pointer to data to the new object, leaving the moved object in an moved from state, therefore not copying all the data. This would be C++-valid.
Try googling for move semantics, rvalue, perfect forwarding.