Is auto_ptr deprecated?

dimba picture dimba · Mar 8, 2010 · Viewed 41.9k times · Source
  1. Will auto_ptr be deprecated in incoming C++ standard?
  2. Should unique_ptr be used for ownership transfer instead of shared_ptr?
  3. If unique_ptr is not in the standard, then do I need to use shared_ptr instead?

Answer

UPDATE: This answer was written in 2010 and as anticipated std::auto_ptr has been deprecated. The advice is entirely valid.

In C++0x std::auto_ptr will be deprecated in favor of std::unique_ptr. The choice of smart pointer will depend on your use case and your requirements, with std::unique_ptr with move semantics for single ownership that can be used inside containers (using move semantics) and std::shared_ptr when ownership is shared.

You should try to use the smart pointer that best fits the situation, choosing the correct pointer type provides other programmers with insight into your design.