title: vector deep copy using a functor or lambda
body: <p>I am trying to make deep copies of vectors of std::shared_ptr. Unfortunately I can't use objects, as most of those pointers are to polymorphic objects.</p>
  
  <p>I've tried using the clone method adapted to std::shared_ptr:</p>
  
  <pre><code>std::shared_ptr&lt;Action&gt; Clone ( )
  {
    return std::make_shared&lt;Action&gt;( *this );
  }
  </code></pre>
  
  <p>But I am still running into problems.
  So, I was wondering (can't remember where I've seen it) how can I copy the contents of one vector into another, by using a function or a lambda that performs the actual deep copy.</p>
  
  <p>Let me rephrase, I don't want just the pointers, I want a copy of the pointed objects too.
  The typical assignment </p>
  
  <pre><code>operator=
  </code></pre>
  
  <p>for std::vector appears to copy only the pointers as one would normally expect.</p>
  
  <p>I'm using GCC 4.8 with C++11 in case it can offer any more elegant or minimalistic approach.</p>
  
  <p>The actual purpose is so that copy constructors of classes that have those vectors, provide non-shared objects but same or different pointers:</p>
  
  <pre><code>class State
  {
  public:
    State ( const State &amp; rhs )
    {
      // Deep copy Actions here?
    }
  
  
  private:
    std::vector&lt;std::shared_ptr&lt;Action&gt;&gt; _actions;
  };
  </code></pre>
  
  <p>Many thanks to anyone who can help!</p>