Should I std::move a shared_ptr in a move constructor?
问题 Consider: #include <cstdlib> #include <memory> #include <string> #include <vector> #include <algorithm> #include <iterator> using namespace std; class Gizmo { public: Gizmo() : foo_(shared_ptr<string>(new string("bar"))) {}; Gizmo(Gizmo&& rhs); // Implemented Below private: shared_ptr<string> foo_; }; /* // doesn't use std::move Gizmo::Gizmo(Gizmo&& rhs) : foo_(rhs.foo_) { } */ // Does use std::move Gizmo::Gizmo(Gizmo&& rhs) : foo_(std::move(rhs.foo_)) { } int main() { typedef vector<Gizmo>