title: std::shared_ptr deep copy object
body: <p>Can't find much on that for C++11 but only on boost.</p>
  
  <p>Consider the following class:</p>
  
  <pre><code>class State
  {
     std::shared_ptr&lt;Graph&gt; _graph;
  
   public:
  
      State( const State &amp; state )
      {
          // This is assignment, and thus points to same object
          this-&gt;_graph = std::make_shared&lt;Graph&gt;( state._graph ); 
  
          // Deep copy state._graph to this-&gt;_graph ?
          this-&gt;_graph = std::shared_ptr&lt;Graph&gt;( new Graph( *( state._graph.get() ) ) );
  
          // Or use make_shared?
          this-&gt;_graph = std::make_shared&lt;Graph&gt;( Graph( *( state._graph.get() ) ) );
      }   
  };
  </code></pre>
  
  <p>Suppose <em>class Graph</em> does have a copy constructor:</p>
  
  <pre><code>Graph( const Graph &amp; graph )
  </code></pre>
  
  <p>I do not want to have <strong>this->_graph</strong> point/share the same object! 
  Instead, I want <strong>this->_graph</strong> to deep copy the object from <strong>state._graph</strong>, into my own <strong>this->_graph</strong> duplicate.</p>
  
  <p>Is the way above the correct way of going about this?</p>
  
  <p><a href="http://en.cppreference.com/w/cpp/memory/shared_ptr/make_shared" rel="noreferrer">Documentation of std::make_shared</a> notes that:</p>
  
  <blockquote>
    <p>Moreover, f(shared_ptr(new int(42)), g()) can lead to memory leak
    if g throws an exception. This problem doesn't exist if make_shared is
    used.</p>
  </blockquote>
  
  <p>Is there another way of going about this, safer or more reliable?</p>