unique_ptr (constructor) @ cppreference
unique_ptr( pointer p, /* see below */ d1 ) noexcept;
(3)
unique_ptr( pointer p, /* see below */ d2 ) noexcept;
(4)
Here are 2 constructors and the description for the case Deleter is non-reference
a) If D is non-reference type A, then the signatures are:
unique_ptr(pointer p, const A& d) noexcept;
(1) (requires that Deleter is nothrow-CopyConstructible)
unique_ptr(pointer p, A&& d) noexcept;
(2) (requires that Deleter is nothrow-MoveConstructible)
I checked both gcc and llvm code but I don't see nothrow
requirement is enforced. Constructors 3-4 are marked noexcept
so it makes sense that the Deleter
should not throw when its constructors are called. But I'm not sure why in the example they provided the constructors are not marked as noexcept
.
struct D { // deleter
D() {};
D(const D&) { std::cout << "D copy ctor\n"; }
D(D&) { std::cout << "D non-const copy ctor\n";}
D(D&&) { std::cout << "D move ctor \n"; }
void operator()(Foo* p) const {
std::cout << "D is deleting a Foo\n";
delete p;
};
};