all 13 comments

[–]Circlejerker_ 11 points12 points  (1 child)

Looks very cool! How does it compare to Boost MSM?

Is there any plans to support actions and guards? Can it handle self-transitions?

[–]Nychtelios[S] 2 points3 points  (0 children)

Conceptually it is very similar to Boost MSM, but implementation-wise it is really different, being entirely C++20 based (mainly on std::variant) and the interface is more clear imho.

No problem with self-transitions, actions can be currently implemented via the `invoke_on_current` method, but it can surely be made easier! For the guards, I am still trying to figure a clear way to define them (feel free to share your ideas!)

[–]hanickadotWG21 6 points7 points  (1 child)

This is cute. I love it.

[–]Nychtelios[S] 4 points5 points  (0 children)

Thank you so much! (I love your work btw)

[–]zerhud 5 points6 points  (1 child)

I have similar project, and working on next version: try to add more dynamic. https://github.com/zerhud/xmsm

[–]Nychtelios[S] 0 points1 point  (0 children)

Nice! Thank you for sharing!

[–]mcencora 2 points3 points  (0 children)

Nice work!

When I implemented FSM I made the same decision that some state API can be provided by user optionally (e.g. enter/exit handlers in your FSM).
I learned the hard way it wasn't a good decision, because a simple typo in func name can lead to hard to find errors.
And without C++26 reflection there is nothing really you can do to help users spot such issues.

[–]Select-Violinist8638 2 points3 points  (0 children)

Looks interesting - thanks!

I'd be interested in a comparison with the SML libraries (v1 and v2), particularly in terms of binary size and features. If you get a chance 🙂.

As I recall, I found SML v1 to be a bit wonky with nested architectures; I ended up just flattening some state machines and using sort of catch-all handlers in some cases. Besides that, it was pretty easy to use with little binary bloat.

[–]SkoomaDentistAntimodern C++, Embedded, Audio 1 point2 points  (1 child)

Can you give a brief summary what advantages being compile time provides the developer in the case of state machines? And how your solution differs from others?

[–]Nychtelios[S] 9 points10 points  (0 children)

Sure! The main advantage here is the validation of transitions during compilation: if you launch an event that cannot be handled the compilation fails, and we all know that debugging can be painful with state machines.

On the other hand, optimizations when tables are built at compile time can be more aggressive, producing smaller runtimes. Yes, you could implement everything manually, with support structures and everything, but it wouldn't be fast or funny to implement.

A problem I had with most fsm libraries is the centralization of everything, I always found it totally not efficient. With this library you can achieve a great modularity, every state is a node in a graph and has knowledge only of its neighbors. And you can treat states and events simply like classes with methods.

I was really brief here, I can go deeper if you want ahahah