Live data from Hacker News

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

github.com

1–10 of 37 posts

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

#1
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 HN: CXXStateTree – A modern C++ library for hierarchical state machines
github.com

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

#2
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.

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

#3

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.

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

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

#8
post #6

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

No, it is the way. Edit: no one has time for inventing unique names for include guards.

Does anyone write those by hand anyway in any kind of project the size where it would matter?

#pragma once is broken by design

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

#9
post #8

Earlier quoted context omitted.

No, it is the way. Edit: no one has time for inventing unique names for include guards.

Does anyone write those by hand anyway in any kind of project the size where it would matter? #pragma once is broken by design

I don't understand what you're saying here. #pragma once does the job that include guards used to do, but with less work, and in a less error prone way. How is it broken, and how is the size of a project relevant?

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

#10
post #6

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

No, it is the way. Edit: no one has time for inventing unique names for include guards.

> No, it is the way.

No, this is completely wrong. Pragma once is non-standard compiler directive. It might be supported by some compilers such as msvc but technically it is not even C++.

There are only two options: include guards, and modules.

Post reply on HN