The documentation says that Deleter should be:
- nothrow constructible
- nothrow callable (because it's called from
~unique_ptr() noexcept
- nothrow destructible (for the reason above)
My question is why uniqut_ptr
is defined to allow a Deleter
that may throw. E.g. the following Deleter
is allowed by all unique_ptr
constructors:
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;
};
};