Rob Stewart wrote:
On July 29, 2014 3:39:16 AM EDT, "Klaim - Joël Lamotte"
wrote: On 29 Jul 2014 02:33, "Rob Stewart"
wrote: ... It would be nice if get_symbol returned a smart pointer that contained a shared_ptr to the library. When all such references are released, the library can be unloaded.
I disagree. In my experience it would be more useful if it contained a weak_ptr to the library, with a centralised system keeping all loaded libraries alive and allowing the used to unload the library explicitely. ... Please explain. Using a weak_ptr means each access must be tested, with synchronized access, to boot, versus assurance of validity with the shared_ptr.
It's possible to support both uses. If get_symbol is defined as
class library;
template<class F> shared_ptr<F> get_symbol( shared_ptr<library> pl )
{
return shared_ptr<F>( pl, static_cast