boost-ext / sml

C++14 State Machine library
https://boost-ext.github.io/sml
Boost Software License 1.0
1.16k stars 179 forks source link

Multiple anonymous transitions, does not work as expected #98

Open omicronns opened 7 years ago

omicronns commented 7 years ago

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?

inductiveload commented 2 years ago

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

omicronns commented 2 years ago

Probably it was fixed.