I will talk specifically about the pointer vector, which is responsible for managing the lifetime of these objects, because this is the only case where the pointer vector is clearly an dubious choice.
There are much better alternatives. In particular:
std::vector<std::shared_ptr<foo>> v;
and
std::vector<std::unique_ptr<foo>> v;
and
boost::ptr_vector<foo> v;
The above versions tell the user how they care about the lifetime of objects. Instead, using raw pointers can delete pointers more or less than once, especially if the code changes over time or exceptions occur.
If you use an interface such as "shared_ptr" or "unique_ptr", this will automatically document the life cycle management for the user. When you use raw pointers, you should clearly document how you manage the life cycle of objects, and hope that the right people read the documentation at the right time.
The advantages of using raw pointer vectors are that you have more flexibility in managing your life cycle and that you can get rid of some performance and space constraints.
Peter
source share