Subject: Re: [boost] News about proposed Boost.Application library
From: Klaim - JoÃ«l Lamotte (mjklaim_at_[hidden])
Date: 2014-07-30 07:49:56
On Wed, Jul 30, 2014 at 1:29 PM, Peter Dimov <lists_at_[hidden]> wrote:
> Klaim - JoÃ«l Lamotte wrote:
> I might have misunderstood what Peter suggested: I thought he suggested
>> that get_symbol<> would return a smart pointer (not shared_ptr) that would
>> _internally_ contain a shared_ptr to the plugin and the access to the data.
> No, get_symbol returns a 'real' shared_ptr in my suggestion.
> shared_ptr<library> p = load_library( "mylib.so" );
> shared_ptr<void()> p2 = get_symbol<void()>( p, "myfunction" );
> (*p2)(); // calls myfunction() in mylib.so
> By creating p2 using the aliasing constructor of shared_ptr, you can have
> p2 and p share ownership of the loaded library.
> template<class Y> shared_ptr(const shared_ptr<Y>& r, T *p) noexcept;
> Effects: Constructs a shared_ptr instance that stores p and shares
> ownership with r.
> Postconditions: get() == p && use_count() == r.use_count()
> [ Note: To avoid the possibility of a dangling pointer, the user of
> this constructor must ensure that p remains valid at least until the
> ownership group of r is destroyed. âend note ]
Ok, thanks now I see what you actually meant, sorry for the noise.
Could you clarify what would happen here:
shared_ptr<library> p = load_library( "mylib.so" );
p2 = get_symbol<void()>( p, "myfunction" );
} // p is destroyed
(*p2)(); // ?
A system-specific error or no error (which would mean that *p is kept
> Unsubscribe & other changes: http://lists.boost.org/
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk