c++ - Is there any use for unique_ptr with array? -


std::unique_ptr has support arrays, instance:

std::unique_ptr<int[]> p(new int[10]); 

but needed? more convenient use std::vector or std::array.

do find use construct?

some people not have luxury of using std::vector, allocators. people need dynamically sized array, std::array out. , people arrays other code known return array; , code isn't going rewritten return vector or something.

by allowing unique_ptr<t[]>, service needs.

in short, use unique_ptr<t[]> when need to. when alternatives aren't going work you. it's tool of last resort.


Comments