Boost logo

Boost Users :

Subject: Re: [Boost-users] Delegating to boost::function with arbitrary signature
From: Alexander Lamaison (awl03_at_[hidden])
Date: 2013-12-14 10:56:27


Michael Powell <mwpowellhtx_at_[hidden]> writes:

> On Sat, Dec 14, 2013 at 9:25 AM, Bjorn Reese <breese_at_[hidden]> wrote:
>> On 12/14/2013 03:49 PM, Alexander Lamaison wrote:
>>
>>> I'm trying to create something like a `boost::function`, but with an
>>> extra 'smart handle' tucked inside, which controls the lifetime of a
>>> resource the functions needs to execute correctly.
>>
>>
>> The two aspects (resource life-time and generic signatures) should
>> probably be handled separately.
>>
>> Regarding resource life-time, a common pattern is to bind to a member
>> function on an object obtained via shared_from_this(). Here is an
>> example from Boost.Asio:
>
> I tend to agree with this application of the pattern:
> dependency-injection and/or inversion-of-control, or in this case,
> method-injection.
>
> Trust me, from industry best practice, as well as experience, you'll
> be glad you did, because you can keep the concerns a) loosely coupled,
> and b) more concise, single-responsibility, closer to the problem they
> are actually trying to solve.
>
>> http://www.boost.org/doc/html/boost_asio/tutorial/tutdaytime3.html

I'm probably being dense, but I don't see how this applies to what I'm
trying to do.

My 'smart handle' is just a `shared_ptr` controlling the
loading/unloading of a DLL from which I load a function by name. I want
to expose that function as a callable object, and the library needs to
remain loaded as long as anyone might call it.

Alex

-- 
Swish - Easy SFTP for Windows Explorer (http://www.swish-sftp.org)

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