←back to thread

48 points zigrazor | 1 comments | | HN request time: 0.228s | 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
dgan ◴[] No.44523973[source]
i am by no means a C++ expert, but isn't "pragma once" frowned upon?
replies(5): >>44524039 #>>44526928 #>>44526935 #>>44528279 #>>44529097 #
kookamamie ◴[] No.44524039[source]
No, it is the way. Edit: no one has time for inventing unique names for include guards.
replies(2): >>44524438 #>>44524781 #
motorest ◴[] No.44524781[source]
> 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.

replies(2): >>44524794 #>>44524905 #
quietbritishjim ◴[] No.44524794[source]
What major compiler does not support it?
replies(1): >>44524934 #
motorest ◴[] No.44524934[source]
> What major compiler does not support it?

The whole point is that it's not supported and it's not standard, thus using #pragma once needlessly introduced the risk of having the code break.

You should ask yourself what are you doing and why are you using non-standard constructs that may or may not work, specially when it's rather obvious and trivial to just use include guards. Using #pragma once isn't even qualify as being clever to gain anything.

replies(3): >>44525100 #>>44525869 #>>44527946 #
1. AlotOfReading ◴[] No.44527946[source]
Lots of things in C/C++ are nonstandard or optional, like the existence of optimization flags. Nevertheless, it's supported by literally every compiler I can think of for at least the last decade. I had to get into weird interpreters written in Python for university projects before I found anything that didn't support it.

Plus, it's nicer to read than #ifndef FOO_BAR_BAZ_PROJ_DIR1_DIR2_DIR3_FILE_H

#endif /* FOO_BAR_BAZ_PROJ_DIR1_DIR2_DIR3_FILE_H */

On every file.