I have a state machine with states A, B and C. C handles event e directly, while A and B do not, but I want to fallback to a default handler (what Samek calls the "ultimate hook" pattern) for event e (that will be called when no handler is found in states A and B). However, with Boost MSM, I cannot implement this handler at the state machine level, but must introduce an additional container state S containing A, B and C.
Is there a way to implement event handlers directly at the state machine level itself instead of needing this container state?
You can do that using
no_transitionhandler.Let's say the event E is defined as follows:
Here is an example of no_transition handler for event E:
However, Boost.MSM requires no_transition handler for other types due to meta-programming.
So you need to define the no_transition handler for other events as follows:
You might think that you can do as follows:
It doesn't work because the no_transition handler instantiates not only E but also other event that doesn't have the member variable
val.Here is an example of whole working code based on your question:
Live Demo: https://wandbox.org/permlink/NWvuaetwFAm5Nm23