I have a boost::shared_ptr
with a custom deleter attached. When converting this to weak_ptr
is the deleter information lost? If yes, how do I reattach the same deleter to shared_ptr
-s acquired from weak_ptr::lock()
method?
The feature I am implementing is a container of weak_ptr
-s pointing to the alive instances of some type. I need the custom deleter to remove the container entry for objects being deleted.
No, the custom deleter is never lost.
When you lock()
your weak_ptr
you regain a shared_ptr
with the same custom deleter (and other attributes) that the one you use to create the weak_ptr
from in the first place.
However, If no shared_ptr
references your weak_ptr
any longer, the lock()
will fail and return a null shared_ptr
.
That is, you shouldn't have to care about the custom deleter. If you specified it upon the shared_ptr
creation, it will be called when the last related shared_ptr
will be freed.