sml icon indicating copy to clipboard operation
sml copied to clipboard

Multiple anonymous transitions, does not work as expected

Open omicronns opened this issue 8 years ago • 2 comments

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?

omicronns avatar Mar 24 '17 09:03 omicronns

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;
}

Try it online

inductiveload avatar Jul 25 '22 16:07 inductiveload

Probably it was fixed.

omicronns avatar Jul 28 '22 08:07 omicronns