specialise `std::default_delete` for `std::shared_ptr`

我的未来我决定 提交于 2019-12-05 06:20:27
ForEveR

default_delete should be defined in std namespace and it's ok to specialize entities from std namespace.

namespace std {
template<class T> struct default_delete;
template<class T> struct default_delete<T[]>;

However, your specialization violates some of the requirements of std::default_delete and thus is UB. Quotes about this thing are here (thanks to R. Martinho Fernandes).

However, shared_ptr is not specified to use default_delete.

~shared_ptr();

Effects:

  • If *this is empty or shares ownership with another shared_ptr instance (use_count() > 1), there are no side effects.

  • Otherwise, if *this owns an object p and a deleter d, d(p) is called.

  • Otherwise, *this owns a pointer p, and delete p is called.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!