←back to thread

48 points zigrazor | 4 comments | | HN request time: 0.994s | source

Hi HN!

I've built [CXXStateTree](https://github.com/ZigRazor/CXXStateTree), a modern C++ header-only library to create hierarchical state machines with clean, intuitive APIs.

It supports: - Deeply nested states - Entry/exit handlers - State transitions with guards and actions - Asynchronous transitions with `co_await` (C++20 coroutines) - Optional runtime type identification for flexibility

It's ideal for complex control logic, embedded systems, games, robotics, and anywhere you'd use a finite state machine.

I’d love feedback, use cases, or contributions from the community!

Repo: https://github.com/ZigRazor/CXXStateTree

Show context
jeffreygoesto ◴[] No.44487283[source]
Nice and compact. I only wound have two nitpicks:

The Readme sais "zero heap allocations" but the code uses list and unordered map and moves, did you mean "zero allocations after state tree building"?

Also for embedded it would be useful to separate all in/out, dot export etc. to a second library that you can omit on small targets.

replies(1): >>44487438 #
1. zigrazor ◴[] No.44487438[source]
yes, it means "zero allocations after state tree building". Thank you for the suggestions, I think we could separate target with compilation switch. If you want you can open an issue on the repo. Thank you so much
replies(1): >>44531576 #
2. rpaddock ◴[] No.44531576[source]
In some Embedded areas where safety is of high concern following the Motor Industry Software Reliability Association (MISRA) guidelines is a requirement.

There may be no heap at all and memory must be pre-allocated at system initialization. Otherwise CXXStateTree sounds like it could be very useful in my Embedded devices, which rarely have enough Flash or RAM space, which is the nature of the work.

https://misra.org.uk

replies(1): >>44531824 #
3. zigrazor ◴[] No.44531824[source]
I think it is possible to create a version with 0 heap allocation, try to open an issue with this feature request, we can see how to that togheter
replies(1): >>44535917 #
4. rpaddock ◴[] No.44535917{3}[source]
Thank you.