Non-ownership copies of std::unique_ptr
问题 There's two containers: owner and non-owner of resource. As I have only 1 owner, I suppose I need unique_ptr. class OwnershipContainer { public: void add(std::unique_ptr<Obj> obj) { objects.push_back(std::move(obj)); } Obj* get(std::size_t i) { return objects[i].get(); } private: std::vector<std::unique_ptr<Obj>> objects; }; What of kind of pointer i have to use for non-owner container? First thought was raw pointer. But i cannot give guarantee that lifetime of Obj match or exceed lifetime of