From: Tobias Schwinger (tschwinger_at_[hidden])
Date: 2006-10-26 17:19:14
Aristid Breitkreuz wrote:
>>Well, the experiment was driven by the question whether it would be
>>possible to add more features of spirit::rule to a macro-based
>>replacement that uses typeof instead of virtual dispatch (see
>>boost/spirit/utility/rule_parser.hpp, note: no named parameters in
>>there, yet) without compromising the interface or even making it
> Oh. Virtual dispatch is still necessary for recursion, right?
Of course you'll need a static call to recurse and a dynamic one to return at /some/ point (since the compiler can't inline forever), but you do not need virtual dispatch, which involves at least two dynamic calls (including the return) plus the vtable lookup.
It works for the same reason CRTP does -- the laziness of template instantiation makes it possible. Here is some code that attempts to illustrate how:
X & ref_that;
explicit A(X & that)
'A<B>::do_' and 'B::do_' recurse back and forth.
Spirit's subrule template also works without virtual dispatch (however, the setup happens expression level).
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk