-
shared_ptr/weak_ptr
allow to keep a weak reference on an object but I can't prevent someone who receives a weak to convert it and store it as a shared. So I lose the control of the object lifetime . -
unique_ptr
is ok to control the lifetime of the object, but does not have a weak reference mechanism.
I couldn't find a standard way to have the benefits of lifetime control and weak reference at the same time. I can't believe that I'm the only one to encounter this problem.
Is there anything in the standard or in boost that would allow this behavior? Or is there a pattern allowing this without rewriting a complete smart_ptr
class?
Aucun commentaire:
Enregistrer un commentaire