Note that there are some explanatory texts on larger screens.

plurals
  1. POGenerating boost bind expressions
    text
    copied!<p>I have the following code (or something equivalent to this) to generate bind expressions. I use these expressions along with boost.function_types &amp; luabind.tag_function to expose some functions in our framework to lua.</p> <pre><code>#define BOOST_BIND_ARG(J, I, D) BOOST_PP_CAT(_, BOOST_PP_INC(I)) #define MAKE_BIND_EXPR_GEN(_, N, __) \ template &lt; &gt; \ struct MakeBindExpr &lt; N &gt; \ { \ template &lt; typename FP &gt; \ struct result \ { \ typedef BOOST_TYPEOF_TPL(boost::bind( \ FP(0), BOOST_PP_ENUM(N, BOOST_BIND_ARG, BOOST_PP_EMPTY) \ )) type; \ }; \ \ template &lt; typename FP &gt; \ static typename result &lt; FP &gt;::type get(FP const &amp; f) \ { \ return boost::bind(f, BOOST_PP_ENUM(N, BOOST_BIND_ARG, BOOST_PP_EMPTY)); \ } \ }; \ BOOST_PP_REPEAT_FROM_TO(0, 9, MAKE_BIND_EXPR_GEN, _) </code></pre> <p>This is working. However, is there a less ugly way of implementing MakeBindExpr?</p> <p>The following is what I am able to do now... if you are interested to know...</p> <pre><code>// N is arity // F is function type // FP is function pointer type template &lt; typename N, typename FP &gt; typename MakeBindExpr &lt; N &gt;::template result &lt; FP &gt;::type makeBindExpr(FP const &amp; fp); // FP is a function pointer type template &lt; typename FP &gt; void bind2Lua(char const * const fname, FP const &amp; f) { namespace ft = boost::function_types; using ft::function_type; using ft::function_arity; typedef function_type &lt; FP &gt;::type F; typedef function_arity &lt; F &gt;::type Arity; luabind::tag_function &lt; F &gt;(makeBindExpr &lt; Arity::value &gt;::template get(f)); } deque &lt; string &gt;(string const &amp;, string const &amp;); bind2Lua("names", getNames); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload