Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've been working on this issue and i've somewhat succeeded to make the boost interpreter accept the member function such as:</p> <pre><code>// Registers a function with the interpreter, // will not compile if it's a member function. template&lt;typename Function&gt; typename boost::enable_if&lt; ft::is_nonmember_callable_builtin&lt;Function&gt; &gt;::type register_function(std::string const&amp; name, Function f); // Registers a member function with the interpreter. // Will not compile if it's a non-member function. template&lt;typename Function, typename TheClass&gt; typename boost::enable_if&lt; ft::is_member_function_pointer&lt;Function&gt; &gt;::type register_function(std::string const&amp; name, Function f, TheClass* theclass); </code></pre> <p>The enable_if statement is used to prevent the use of the wrong method at the compile time. Now, what you need to understand :</p> <ul> <li>It uses the boost::mpl to parse trough the argument's parameter types of the callable builtin (which is basically a function pointer)</li> <li>Then, prepares a fusion vector at the compile-time (which is a vector that can stock different objects of different types at the same time)</li> <li>When the mpl is done parsing every arguments, the "parsing" apply method will fork in the "invoke" apply method, following the templates.</li> <li>The main issue is that the <strong>first argument of a member callable builtin is the object which holds the called method.</strong> </li> <li>As far a I know, the mpl cannot parse the arguments of something else than a callable builtin (i.e A Boost::Bind result)</li> </ul> <p>So, what needs to be done is simply add one step to the "parsing" apply, which would be to add the concerned object to the apply loop! Here it goes:</p> <pre><code>template&lt;typename Function, typename ClassT&gt; typename boost::enable_if&lt; ft::is_member_function_pointer&lt;Function&gt; &gt;::type interpreter::register_function( std::string const&amp; name, Function f, ClassT* theclass); { typedef invoker&lt;Function&gt; invoker; // instantiate and store the invoker by name map_invokers[name] = boost::bind(&amp;invoker::template apply_object&lt;fusion::nil,ClassT&gt; ,f,theclass,_1,fusion::nil()); } </code></pre> <p>in interpreter::invoker</p> <pre><code>template&lt;typename Args, typename TheClass&gt; static inline void apply_object( Function func, TheClass* theclass, parameters_parser &amp; parser, Args const &amp; args) { typedef typename mpl::next&lt;From&gt;::type next_iter_type; typedef interpreter::invoker&lt;Function, next_iter_type, To&gt; invoker; invoker::apply( func, parser, fusion::push_back(args, theclass) ); } </code></pre> <p>This way, it will simply skip the first argument type and parse everything correctly. The method can be called this way: <code>invoker.register_function("SomeMethod",&amp;TheClass::TheMethod,&amp;my_object);</code></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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