Is anyone aware of an implementation of shared_ptr
and weak_ptr
together with a lazy initialization partner? The requirements of the classes were:
A
lazy_ptr
class that allows a client to construct the object later (if at all), without needing the constructor implementationA
weak_lazy_ptr
class that has three possible states: not yet constructed (won't lock to ashared_ptr
), constructed (will lock to ashared_ptr
) and destroyed (won't lock to ashared_ptr
)
I created some classes that didn't do the job completely a while ago (see CVu article here) that used shared_ptr
and weak_ptr
in their implementation. The main problems with a model that USES shared and weak pointers instead of integrating with them follow:
Once all
lazy_ptr
objects go out of scope, any weak references can no longer be locked, even if other clients are holdingshared_ptr
versionsConstruction of objects on different threads can't be controlled
I'd appreciate any pointers to other attempts to reconcile these problems, or to any work in progress there may be in this area.
shared_ptr<boost::optional<T>>
, is that right? – Verbenaboost::optional
does allow deferred construction, butboost::shared_ptr
allows that too, so both are not needed, if I understand you. – Seriousshared_ptr
's refer to the initialized object. – Verbena