title: std::unique_ptr vs std::shared_ptr vs std::weak_ptr vs std::auto_ptr vs raw pointers
body: <p>What are the equivalent uses of each smart pointer in comparison to similar (but not limited to) some advanced techniques using raw pointers?</p>
  
  <p>My understanding is minimal, but from what I can gather:</p>
  
  <ul>
  <li><strong>Raw Pointers:</strong> Only use if you really, really, really, really, know what you are doing and have carefully hidden usage behind an interface.</li>
  <li><strong>std::auto_ptr:</strong> Obsolete never use.</li>
  <li><strong>std::unique_ptr:</strong> Singleton pointer that transfers ownership upon assignment.</li>
  <li><strong>std::shared_ptr:</strong> Reference counted pointer that does not transfer ownership upon assignment but increments its reference count. When all references leave scope or are explicitly <code>std::shared_ptr::reset</code> the underlying <code>deallocator</code> is called.</li>
  <li><strong>std::weak_ptr:</strong> A sub-type <code>std::shared_ptr</code> that does not increment the reference count and is invalidated when its parent <code>std::shared_ptr</code> no longer exists. May return and invalid reference. Always check before using.</li>
  </ul>
  
  <p><strong>RAW POINTER EQUIVALENT EXAMPLES</strong></p>
  
  <p><strong>Reference counting, cache implementations:</strong> <code>std::map&lt;std::string, std::pair&lt;long, BITMAP*&gt; &gt; _cache;</code></p>
  
  <p><strong>Singletons with transfer of ownership:</strong></p>
  
  <pre><code>class Keyboard {
  public:
  //...
      static Keyboard* CreateKeyboard();
      ~Keyboard();
  //...
  private:
  //...
      Keyboard();
      static Keyboard* _instance;
  //...
  };
  </code></pre>
  
  <p><strong>Aggregate Containers, no ownership:</strong> Spatial partitioning graphs and trees, iterative containers, etc.</p>
  
  <p><strong>Composite Containers, ownership:</strong> Large objects.</p>
  
  <p><strong>--EDIT--</strong></p>
  
  <p>As I am working I came upon an interesting case, DeadMG pointed out that smart pointers are supposed to be used as easy abstractions to take care of resource management; what about file-scope objects that can not be created on the heap at the point of declaration but instead must be created at a later time?</p>