<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">2013/12/16 Alexander Lamaison <span dir="ltr"><<a href="mailto:awl03@doc.ic.ac.uk" target="_blank">awl03@doc.ic.ac.uk</a>></span><br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"> TONGARI J <<a href="mailto:tongari95@gmail.com">tongari95@gmail.com</a>> writes:<br><div class="im"><br> > �template<typename Signature><br> > �class library_function<br> > �{<br> > �public:<br> > � � �library_function(<br> > � � � � �shared_ptr<HMODULE> library, Signature* library_funtion)<br> > � � � � �:<br> > � � �m_library(library),<br> > � � �m_function(library_function)<br> > � � �{}<br> ><br> > � � �operator Signature*() const { return m_function; }<br> ><br> ><br> > �private:<br> > � � �shared_ptr<HMODULE> m_library;� � �Signature*�m_function;<br> > �};Note: code not tested<br> <br> </div>This works well. �The key was `operator Signature*()`. �Clever idea,<br> thanks!<br> <br> I didn't expect it to work because I though `boost::function` would pull<br> out the `Signature*` via the cooersion operator, and then the<br> `library_function` would be destroyed before the call was made.<br> However, this code proves that it has the desired behaviour, so it must<br> be keeping a copy of the `library_function` instance inside<br> `boost::function`: <a href="http://ideone.com/BZvuk9" target="_blank">http://ideone.com/BZvuk9</a>.<br> <br> I didn't use`make_library_function` because inferring the signature<br> from the raw function isn't something I need.<br> <br> If you would like to add this answer to the Stack Overflow qusetion,<br> I'll happily give you the brownie points :)<br></blockquote><div><br></div><div>Done: <a href="http://stackoverflow.com/a/20614403/2969631">http://stackoverflow.com/a/20614403/2969631</a>�</div><div><br></div><div>BTW, the reason why I knew this trick is because I implemented this:</div> <div><br></div>� � <a href="http://tinyurl.com/mptekbr">http://tinyurl.com/mptekbr</a></div><div class="gmail_quote"><br></div><div class="gmail_quote">and it credits to Proto.</div></div></div>