The std::unique_ptr
template has two parameters: the type of the pointee, and the type of the deleter. This second parameter has a default value, so you usually just write something like std::unique_ptr<int>
.
The std::shared_ptr
template has only one parameter though: the type of the pointee. But you can use a custom deleter with this one too, even though the deleter type is not in the class template. The usual implementation uses type erasure techniques to do this.
Is there a reason the same idea was not used for std::unique_ptr
?
unique_ptr
is a much simpler and lighter-weight smart pointer thanshared_ptr
. – Antananarivo