std::unique_ptr
- is better to use when you want to transfer ownership
- has no overhead (memory or CPU)
std::vector:
- is better when the initial size is unknown as it allows for dynamic growth
- keeps track of the size for you
Am I missing something?
I'm pretty sure the default deleter does a delete[] on array unique_ptr's. The template is specialized for array types.
[background=rgb(250, 251, 252)]Only difference is that the unique_ptr enforces the ownership a bit more by not being implicitly copyable.[/quote][/background]
First of all, the title of this message is very misleading.
Fortunately there is a good general guideline:
Use std::vector!
If you need to know why, please search for some of the discussion about arrays vs. vector and remove all arguments against arrays that concern lifetime management of the array's memory.
[/quote]
I don't understand this. A vector is a one dimensional array. So for the one dimensional case, there are no differences by definition.
Thanks for some feed-back, but there is still no explanation on why I should use std::vector instead of std::unique_ptr for managing vectors.