Is the sole difference between boost::scoped_ptr<T>
and std::unique_ptr<T>
the fact that std::unique_ptr<T>
has move semantics whereas boost::scoped_ptr<T>
is just a get/reset smart pointer?
相关问题
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
- What uses more memory in c++? An 2 ints or 2 funct
相关文章
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- Which is the best way to multiply a large and spar
- C++ default constructor does not initialize pointe
- Selecting only the first few characters in a strin
- What exactly do pointers store? (C++)
- Converting glm::lookat matrix to quaternion and ba
- What is the correct way to declare and use a FILE
No, but that is the most important difference.
The other major difference is that
unique_ptr
can have a destructor object with it, similarly to howshared_ptr
can. Unlikeshared_ptr
, the destructor type is part of theunique_ptr
's type (the way allocators are part of STL container types).A
const unique_ptr
can effectively do most of what ascoped_ptr
can do; indeed, unlikescoped_ptr
, aconst unique_ptr
cannot be rebound with areset
call.Also,
unique_ptr<T>
can work on aT
which is an incomplete type. The default deleter type requires thatT
be complete when you do anything to theunique_ptr
that potentially invokes the deleter. You therefore have some freedom to play games about where that happens, depending on the situation.unique_ptr
owns an object exclusively.It is non-copyable but supports transfer-of-ownership. It was introduced as replacement for the now deprecatedauto_ptr
.scoped_ptr
is neither copyable nor movable. It is the preferred choice when you want to make sure pointers are deleted when going out of scope.