I would like to reuse the code by writing a proto conversion that is templated by a function pointer:
template <typename Ret, typename A0, typename A1, Ret func(A0,A1)> struct apply_func : proto::callable {
However, the function itself is polymorphic, so I do not want to indicate its exact signature.
A simplified version of what I would like my code to look like (I use external transforms for a technical reason, which, in my opinion, is not related to my current question - I could not get recursion to work without them):
template<typename R, typename A0, typename A1> R plus_func(A0 lhs, A1 rhs) { return lhs+rhs; } template<typename R, typename A0, typename A1> R minus_func(A0 lhs, A1 rhs) { return lhs-rhs; } struct my_grammar; struct plus_rule : proto::plus<my_grammar, my_grammar> {}; struct minus_rule : proto::minus<my_grammar, my_grammar> {}; struct my_grammar : proto::or_< proto::when<proto::terminal<proto::_>, proto::_value> , proto::when<plus_rule, proto::external_transform > , proto::when<minus_rule, proto::external_transform > > {}; struct my_external_transforms : proto::external_transforms< proto::when<plus_rule, apply_func<plus_func>(my_grammar(proto::_left),my_grammar(proto::_right), proto::_state)> , proto::when<minus_rule, apply_func<minus_func>(my_grammar(proto::_left),my_grammar(proto::_right), proto::_state)> > {};
This does not compile because there are no arguments in the appy_func template. Is there a solution?