patterncppCritical
Is there any use for unique_ptr with array?
Viewed 0 times
arraywithanyuseforunique_ptrthere
Problem
std::unique_ptr has support for arrays, for instance:std::unique_ptr p(new int[10]);but is it needed? probably it is more convenient to use
std::vector or std::array.Do you find any use for that construct?
Solution
Some people do not have the luxury of using
By allowing
In short, you use
std::vector, even with allocators. Some people need a dynamically sized array, so std::array is out. And some people get their arrays from other code that is known to return an array; and that code isn't going to be rewritten to return a vector or something.By allowing
unique_ptr, you service those needs.In short, you use
unique_ptr when you need to. When the alternatives simply aren't going to work for you. It's a tool of last resort.Context
Stack Overflow Q#16711697, score: 349
Revisions (0)
No revisions yet.