<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">2013/12/16 Alexander Lamaison <span dir="ltr">&lt;<a href="mailto:awl03@doc.ic.ac.uk" target="_blank">awl03@doc.ic.ac.uk</a>&gt;</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 &lt;<a href="mailto:tongari95@gmail.com">tongari95@gmail.com</a>&gt; writes:<br><div class="im"><br>
&gt; �template&lt;typename Signature&gt;<br>
&gt; �class library_function<br>
&gt; �{<br>
&gt; �public:<br>
&gt; � � �library_function(<br>
&gt; � � � � �shared_ptr&lt;HMODULE&gt; library, Signature* library_funtion)<br>
&gt; � � � � �:<br>
&gt; � � �m_library(library),<br>
&gt; � � �m_function(library_function)<br>
&gt; � � �{}<br>
&gt;<br>
&gt; � � �operator Signature*() const { return m_function; }<br>
&gt;<br>
&gt;<br>
&gt; �private:<br>
&gt; � � �shared_ptr&lt;HMODULE&gt; m_library;� � �Signature*�m_function;<br>
&gt; �};Note: code not tested<br>
<br>
</div>This works well. �The key was `operator Signature*()`. �Clever idea,<br>
thanks!<br>
<br>
I didn&#39;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&#39;t use`make_library_function` because inferring the signature<br>
from the raw function isn&#39;t something I need.<br>
<br>
If you would like to add this answer to the Stack Overflow qusetion,<br>
I&#39;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>