sml
sml copied to clipboard
Multiple anonymous transitions, does not work as expected
State machine with multiple anonymous transitions does not work as I would expect.
namespace smt {
using namespace boost::sml;
struct s1;
struct s2;
struct s3;
struct s4;
struct e {};
struct tt {
auto operator()() {
return make_transition_table(
*state<s1> +event<e> = state<s2>,
state<s2> = state<s3>,
state<s3> = state<s4>
);
}
};
}
int main() {
using namespace boost::sml;
sm<smt::tt> s;
s.process_event(smt::e());
assert(s.is(state<smt::s3>)); // ok
assert(s.is(state<smt::s4>)); // fails
return 0;
}
You would expect state machine to be in s4 state, but it gets stuck in s3, so only one anonymous transition is executed. Is it desired behaviour?
This appears to now work:
#include <cassert>
namespace smt {
using namespace boost::sml;
struct s1;
struct s2;
struct s3;
struct s4;
struct e {};
struct tt {
auto operator()() {
return make_transition_table(
*state<s1> +event<e> = state<s2>,
state<s2> = state<s3>,
state<s3> = state<s4>
);
}
};
}
int main() {
using namespace boost::sml;
sm<smt::tt> s;
s.process_event(smt::e());
assert(!s.is(state<smt::s3>)); // ok (in s4, not s3)
assert(s.is(state<smt::s4>)); // ok
return 0;
}
Probably it was fixed.