NuTo
Numerics Tool
|
Note: If you need shared semantics, neither is the right solution. Use a std::container
of std::shared_ptr
s
boost::ptr_container
vs. pointer semantics with unique pointers
vs.
For a std::container
of unique pointers, you would have to implement a deep copy yourself. In Boost, it is built in, using the Clonable Concept
See Boost Ptr Container Documentation.
std::container<std::unique_ptr<MyClass>>
You can't make a shallow copy, because the unique_ptr
is not copy constructible. This is good. With boost pointer containers, you could have copy of the container with dangling pointers after the original container went out of scope.
Don't make shallow copies of owning containers, regardless of how they are implemented.