The difference between boost :: scoped_ptr <T> and std :: unique_ptr <T>

The only difference between boost::scoped_ptr<T> and std::unique_ptr<T> the fact that std::unique_ptr<T> has move semantics, while boost::scoped_ptr<T> is just a smart get / reset pointer?

+46
c ++ unique-ptr scoped-ptr
Nov 20 2018-11-11T00:
source share
2 answers

No, but this is the most important difference.

Another significant difference is that unique_ptr can have a destructor object with it, similar to how shared_ptr can. Unlike shared_ptr , the destructor type is part of the unique_ptr type (the way distributors are part of the STL container types).

+35
Nov 20 '11 at 6:13
source share

unique_ptr belongs to the object exclusively. It is not copied , but supports the transfer of ownership . It has been introduced as a replacement for obsolete auto_ptr .

scoped_ptr not copied or movable . This is the preferred option when you want to make sure that pointers are deleted when you exit the scope.

+21
Nov 20 '11 at 6:16
source share



All Articles