双方unique_ptr并shared_ptr接受定制的析构函数他们所拥有的对象上调用。但在的情况下unique_ptr,析构函数作为一个模板参数传递类,而类型shared_ptr的自定义析构函数将被指定为一个模板参数的构造函数。
template <class T, class D = default_delete<T>> 
class unique_ptr
{
    unique_ptr(T*, D&); //simplified
    ...
};
和
template<class T>
class shared_ptr
{
    template<typename D>
    shared_ptr(T*, D); //simplified
    ...
};
我不明白为什么会有这样的差异。有什么要求?
shared_ptr类型删除器,即的用户shared_ptr不必知道删除器的类型。这具有运行时成本(分配,取消引用),因此不执行unique_ptr(这是无开销的)。例如,请参阅stackoverflow.com/q/6324694/420683