Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You have multiple problem in your code:</p> <ul> <li>you cannot take a template function pointer without specifying its template parameter as the template won't exist until the function get instanciated.</li> <li>second point, Ret(A,B) is a function type not a function pointer type.</li> <li>function pointer are a bit raw as abstraction goes, same can be achieved by a functor which also solve your problem as a polymorphic fnction object is a single, non template type.</li> <li>final technical point, template transform can't use proto::callable, you have to specialize boost::proto::is_callable explicitly. This is due to a langauge limitation on how the inheritance is detected.</li> </ul> <p>Perusing your pseudo code, I'll go for something like :</p> <pre><code>struct plus_func { template&lt;class Sig&gt; struct result; template&lt;class This,class A, class B&gt; struct result&lt;This(A,B)&gt; { typedef /*whatever*/ type; }; template&lt;class A, class B&gt; typename result&lt;plus_func(A const&amp;,B const&amp;)&gt;::type plus_func(A const&amp; lhs, B const&amp; rhs) { return lhs+rhs; } }; struct minus_func { template&lt;class Sig&gt; struct result; template&lt;class This,class A, class B&gt; struct result&lt;This(A,B)&gt; { typedef /*whatever*/ type; }; template&lt;class A, class B&gt; typename result&lt;minus_func(A const&amp;,B const&amp;)&gt;::type plus_func(A const&amp; lhs, B const&amp; rhs) { return lhs-rhs; } }; struct my_grammar; struct plus_rule : proto::plus&lt;my_grammar, my_grammar&gt; {}; struct minus_rule : proto::minus&lt;my_grammar, my_grammar&gt; {}; struct my_grammar : proto::or_&lt; proto::when&lt;proto::terminal&lt;proto::_&gt;, proto::_value&gt; , proto::when&lt;plus_rule, proto::external_transform &gt; , proto::when&lt;minus_rule, proto::external_transform &gt; &gt; {}; struct my_external_transforms : proto::external_transforms&lt; proto::when&lt;plus_rule, apply_func&lt;plus_func&gt;(my_grammar(proto::_left),my_grammar(proto::_right), proto::_state)&gt; , proto::when&lt;minus_rule, apply_func&lt;minus_func&gt;(my_grammar(proto::_left),my_grammar(proto::_right), proto::_state)&gt; &gt; {}; </code></pre> <p>Type returned by each PFO has to be computed or specified. Beware that A,B can be const/ref qualified and may need stripping before doing type computation.</p> <p>Sidenote : external_transform are not required at all for recursive rules. I guess point 4 (template callable) was what made it not work.</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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