Will C++0x support an STL-container of auto_ptrs?
If not, what exactly does the STL-container of shared_ptr do (found in boost)?
Will C++0x support an STL-container of auto_ptrs?
If not, what exactly does the STL-container of shared_ptr do (found in boost)?
Ubuntu Desktop
GCC/G++
Geany (for quick projects)
Anjuta (for larger things)
No, but it almost definitely will support containers of shared_ptrs, which TR1 already supports.Will C++0x support an STL-container of auto_ptrs?
Allow storage of reference counted smart pointers that obey normal copying semantics in a container.If not, what exactly does the STL-container of shared_ptr do (found in boost)?
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
I think C++0x will make it a compile-time error for auto_ptrs to be stored in containers that require specific copy semantics that auto_ptr doesn't adhere to. At the very least it will make it easier for library writers to enforce that.
A shared_ptr when copied does not transfer ownership like auto_ptr and it does not copy the pointed to object. It just creates another shared reference to the object. When a container copies its elements around, you don't want ownership transferred because it might transfer to a temporary copy that is destroyed and therefore the object will be destroyed. You also don't usually want to copy the object itself, otherwise you would just store the object in the container instead of a pointer to it. By using shared_ptr, the object is never actually cleaned up until the last reference to it is destroyed, so as long as the shared_ptr is in the container the objects will always be valid.
Boost also has ptr_vector and other pointer containers that are more specifically designed for containers that hold pointers and manage the memory themselves. Those might be preferable but I'm not sure if they will be standardized.