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.
I've tried using the clone method adapted to std::shared_ptr:
std::shared_ptr<Action> Clone ( )
{
return std::make_shared<Action>( *this );
}
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.
Let me rephrase, I don't want just the pointers, I want a copy of the pointed objects too. The typical assignment
operator=
for std::vector appears to copy only the pointers as one would normally expect.
I'm using GCC 4.8 with C++11 in case it can offer any more elegant or minimalistic approach.
The actual purpose is so that copy constructors of classes that have those vectors, provide non-shared objects but same or different pointers:
class State
{
public:
State ( const State & rhs )
{
// Deep copy Actions here?
}
private:
std::vector<std::shared_ptr<Action>> _actions;
};
Many thanks to anyone who can help!