From: Andreas Huber (ah2003_at_[hidden])
Date: 2003-06-05 17:05:41
> Ooops, sorry ... i was terribly unclear.
> Andreas Huber wrote:
> "boost::fsm no longer uses acyclic visitor! The current double
> dispatch implementation (which was inspired by Aleksey's fsm lib)
> uses one virtual call followed by a linear search for a suitable
> reaction, using one RTTI comparison per visited reaction. Although
> you cannot change the double dispatch implementation itself, you can
> change one aspect of it, i.e. RTTI."
> I mean :
> Where can i find something about cool "double dispatch" used in
> recently submitted FSM code ?
> Or Aleksey's fsm lib sources ?
You can find Aleksey's fsm lib here:
In my library, you can look for simple_state::react_impl() which is the
override for the abstract state_base::react_impl(). The implementation is
quite simple: all reactions are contained in an mpl::list, which is passed
to a function. The function then calls the front reaction. If the reaction
returns that there was a match the result is returned. Otherwise, the
function calls itself again with the front of the list removed. Of course,
there is a specialisation for an empty list which does nothing.
BTW, this double dispatch variant is only "cool" ;-) for cases where the
second stage of the double dispatch has to choose from only a few different
possibilities. That's because the second stage performs a linear search. In
contrast to GOF-visitor, which is essentially constant-time, this variant
becomes slower the more choices it has in the second stage. But it scales
much better in terms of dependencies.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk