Boost :: ptr_vector vs. std :: vector <std :: unique_ptr <T>>?

They do similar things.

What should be considered when choosing between them?

Under what circumstances is either preferred?

+4
source share
1 answer

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

  • Security type - while this is pretty well abstracted for you in boost::ptr_vector , ptr_vector is still implemented in terms of std::vector<void*> .
  • Clear user deletion support - I think you can get user deferral behavior using boost::ptr_vector , but when using std::unique_ptr support becomes more clear (and explicit).
  • It is standard and well supported by compatible C ++ 11 compilers.
+5
source

All Articles