Boost logo

Boost :

Subject: Re: [boost] News about proposed Boost.Application library
From: Peter Dimov (lists_at_[hidden])
Date: 2014-07-30 07:29:29


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 ]


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk