title: Turning vector of shared_ptr into vector of shared_ptr to const
body: <p>Let</p>
  
  <pre><code>class A
  {
      std::vector&lt;std::shared_ptr&lt;int&gt;&gt; v_;
  };
  </code></pre>
  
  <p>Now I'd like to add access to <code>v_</code> using two public member functions</p>
  
  <pre><code>std::vector&lt;std::shared_ptr&lt;int&gt;&gt; const &amp; v() { return v_; }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>std::vector&lt;std::shared_ptr&lt;int const&gt; const &amp; v() const { TODO }
  </code></pre>
  
  <p>I cannot replace <code>TODO</code> with <code>return v_;</code> though.</p>
  
  <p>One option would be to not return a reference but a copy.  Apart from the obvious performance penalty, this would also make the interface somewhat less desirable.</p>
  
  <p>Another option is to make <code>TODO</code> equal to <code>return reinterpret_cast&lt;std::vector&lt;std::shared_ptr&lt;int const&gt;&gt; const &amp;&gt;(v_);</code></p>
  
  <p>My question is, is this undefined behavior?  Or, alternatively, is there a better option, preferably without using <code>reinterpret_cast</code>?</p>