|
Boost Users : |
From: Timmo Stange (ts_at_[hidden])
Date: 2007-02-06 12:40:03
Frank Mori Hess wrote:
> It turns out it doesn't need to be implicitly convertible to shared_ptr at
> all, like I imagined before I read the mem_fn docs. It just needs a
> get_pointer function. I'm currently using a stripped down
> signals::tracked object that is just a thin wrapper around weak_ptr, with
> the following get_pointer function:
That is good news indeed.
> template<typename T>
> T* get_pointer(const signals::tracked<T> &tracked) {return
> tracked.lock().get();}
I wouldn't use lock() but an explicit shared_ptr conversion here as
you will probably want it to throw bad_weak_ptr when the client code
uses a dead reference outside your signals functionality.
I also realized that the abstract base class design is thankfully
unnecessary as a shared_ptr<void> apparently knows what destructor
to call when initialized from the correct pointer type (according
to the docs). I'll see if I can find the time to commit sample code
tonight.
Regards
Timmo Stange
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net