I have not been able to find any documentation about what happens if I pass a null pointer to std::make_unique.
Is an exception thrown?
std::make_unique forwards all the arguments passed to a matching target constructor.
Therefore, if you pass nullptr, it will search for a constructor that accepts nullptr_t (or any matching constructor). If it is not there, it will fail to compile.
class A
{
public:
A(void*) { ... } // could also be A(int*) or template <typename T> A(T*)
};
...
std::make_unique<A>(nullptr); // constructs an A by calling A(void*), passing nullptr.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With