文档说 Deleter 应该是:
- 不扔可构造
- nothrow 可调用(因为它是从
~unique_ptr() noexcept
- nothrow destructible(出于上述原因)
我的问题是为什么uniqut_ptr
定义为允许一个Deleter
可能抛出的。例如,所有构造函数Deleter
都允许以下内容:unique_ptr
struct BadDeleter
{
BadDeleter() noexcept(false) {}
~BadDeleter() noexcept(false) {}
BadDeleter(const BadDeleter&) noexcept(false) {}
BadDeleter(BadDeleter&) noexcept(false) {}
BadDeleter(BadDeleter&&) noexcept(false) {}
void operator()(char* p) const noexcept(false) {
delete p;
};
};