Recently, I came into a situation where I need to copy an object which has a std::unique_ptr type member.
class A {
/* ... */
std::unique_ptr<A> next_;
};
A a0;
A a1{a0};
// compiler error, due to the std::unique_ptr is un-copyable
// but I do need a deep copy!
Of course, I could have a Clone function in A to get me through, but why can't STL just have a deep_ptr to make my life easier (Change next_ to std::deep_ptr<A> next_).
And IMHO, deep copy is a very common demand among the daily developing life, so why does STL lack of such thing std::deep_ptr? Does this concept make no sense especially in some high language level(e.g. the level STL sits at)?
Aucun commentaire:
Enregistrer un commentaire