When creating a std::unique_ptr
in C++, one usually passes the extra delete functor as the template parameter.
But std::shared_ptr
needs it as the constructor parameter.
The answer1 explains that std::unique_ptr
binds the deleter to its type to avoid the runtime overhead of an indirect call for the deleter.
std::shared_ptr
binds it at runtime to make it easier for users to override the deleter2.
Note by default, the default deleter is std::default_deleter<T>
3 :