title: C++ smart pointer const correctness
body: <p>I have a few containers in a class, for example, vector or map which contain
  shared_ptr's to objects living on the heap.</p>
  
  <p>For example</p>
  
  <pre><code>template &lt;typename T&gt;
  class MyExample
  {
  public:
  
  private:
      vector&lt;shared_ptr&lt;T&gt; &gt; vec_;
      map&lt;shared_ptr&lt;T&gt;, int&gt; map_;
  };
  </code></pre>
  
  <p>I want to have a public interface of this class that sometimes returns shared_ptrs to const objects (via <code>shared_ptr&lt;const T&gt;</code>) and sometimes <code>shared_ptr&lt;T&gt;</code> where I allow the caller to mutate the objects.</p>
  
  <p>I want logical const correctness, so if I mark a method as const, it cannot change the objects on the heap.</p>
  
  <p>Questions:</p>
  
  <p>1) I am confused by the interchangeability of <code>shared_ptr&lt;const T&gt;</code> and <code>shared_ptr&lt;T&gt;</code>. When someone passes a <code>shared_ptr&lt;const T&gt;</code> into the class, do I:</p>
  
  <ul>
  <li>Store it as a <code>shared_ptr&lt;T&gt;</code> or <code>shared_ptr&lt;const T&gt;</code> inside the container? </li>
  <li>OR</li>
  <li>Do I change the map, vector types (e.g. insert_element(<code>shared_ptr&lt;const T&gt;</code> obj)? </li>
  </ul>
  
  <p>2) Is it better to instantiate classes as follows: <code>MyExample&lt;const int&gt;</code>? That seems unduly restrictive, because I can never return a <code>shared_ptr&lt;int&gt;</code>?</p>