- for some stl container, if passing by rvalue, it will call move constructor.
vector v; v.push_back(string("hello")); // pass rvalue, call move constructor string s("hello"); v.push_back(move(s)); // element of v takes ownership of v and set s to be null.
- unique pointers and shared pointers.
It’s encouraged to use smart pointers, when doing memory allocation. so we don’t need to worry about memory leak when it goes out of scope.
- unique ptr: exclusive ownership; shared ptr: shared ownership.
for shared ptr: delete happens when last ptr that owns the object goes out of scope
Source: Lesson #5: Move Semantics