4

They do the similar things.

What should be considered when choosing between the two?

Under which circumstances is either one preferred?

Martin Ba
  • 37,187
  • 33
  • 183
  • 337
user2052376
  • 117
  • 1
  • 6

1 Answers1

6

I would prefer std::vector<std::unique_ptr<T>> for several reasons:

  1. Type safety -- while this is pretty well abstracted for you in boost::ptr_vector, ptr_vector is still implemented in terms of std::vector<void*>.
  2. Clear support for custom deleter -- I think you can get custom deleter behavior with a boost::ptr_vector, but the support is clearer (and explicit) when using std::unique_ptr.
  3. It's standard, and well supported by compliant C++11 compilers.
Chad
  • 18,706
  • 4
  • 46
  • 63
  • 1
    I would also add that `vector` is _standard_. People know what it is. Most people probably don't know `boost::ptr_vector` – David Feb 07 '13 at 21:11