Why is `make_unique` disallowed?

Quoting from the original proposal:

T[N]

As of N3485, unique_ptr doesn’t provide a partial specialization for T[N].
However, users will be strongly tempted to write make_unique<T[N]>(). This
is a no-win scenario. Returning unique_ptr<T[N]> would select the primary
template for single objects, which is bizarre. Returning unique_ptr<T[]>
would be an exception to the otherwise ironclad rule that
make_unique<something>() returns unique_ptr<something>. Therefore, this
proposal makes T[N] ill-formed here, allowing implementations to emit
helpful static_assert messages.

The author of the proposal, Stephan T. Lavavej, illustrates this situation in this video on Core C++ (courtesy of chris), starting from minute 1:01:10 (more or less).

Leave a Comment