Show HN: CXXStateTree – A modern C++ library for hierarchical state machines

github.com

39 points by zigrazor 4 days ago


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

wangii - 5 hours ago

how is it better than https://github.com/boost-ext/sml ?

there are about 1 million c++ state machines, and sml happens to be the best, or one of them. how does yours differentiate?

jeffreygoesto - 4 days ago

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.

baymotion - 9 hours ago

Related idea for those using python: https://github.com/baymotion/smax.

dgan - 11 hours ago

i am by no means a C++ expert, but isn't "pragma once" frowned upon?

happyweasel - 13 hours ago

vcpkg it