[ptr_container] ownership

Hello, i need to give up the ownership of a ptr_container (vector here) over its pointers (without assignment to a new ptr_container). Two questions here: 1. Do i really have to write aPtrContainer.release().release()? It looks weird. For me, the function name release() of the container seems confusing since an unassigned aPtrContainer.release() just does the "opposite" of auto_ptr<T>::release(), namely deleting the pointers. ;o) The behavior is more like transfer_ownership() or something similar ($0.02). 2. Beside managing memory, i plan to use ptr_container primarily to propagate const. So, in some cases i need a ptr_container which just doesn't own any given memory. What's the best way to do that? Any comments or pointers to missed docs are welcome. David

David Grüner wrote:
Hello, i need to give up the ownership of a ptr_container (vector here) over its pointers (without assignment to a new ptr_container). Two questions here:
1. Do i really have to write aPtrContainer.release().release()? It looks weird. For me, the function name release() of the container seems confusing since an unassigned aPtrContainer.release() just does the "opposite" of auto_ptr<T>::release(), namely deleting the pointers. ;o)
Right, there is a difference between a single smart pointer and a
container here.
Even if release() in a pointer container returned ptr_container*,
it would still not be consistent with auto_ptr<T>, since that class
returns T*, but ptr_container<T>, would return ptr_container<T>*.
But one could say, why not simply let release() return
container
The behavior is more like transfer_ownership() or something similar ($0.02).
2. Beside managing memory, i plan to use ptr_container primarily to propagate const. So, in some cases i need a ptr_container which just doesn't own any given memory. What's the best way to do that?
use a non-owning clonse_allocator: http://www.boost.org/libs/ptr_container/doc/reference.html#class-view-clone-... -Thorsten
participants (2)
-
David Grüner
-
Thorsten Ottosen