←back to thread

48 points zigrazor | 3 comments | | HN request time: 0.473s | 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 #
hdhdjd ◴[] No.44524438[source]
Does anyone write those by hand anyway in any kind of project the size where it would matter?

#pragma once is broken by design

replies(3): >>44524590 #>>44524788 #>>44526846 #
bogwog ◴[] No.44524590[source]
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?
replies(1): >>44524820 #
1. motorest ◴[] No.44524820[source]
> I don't understand what you're saying here. #pragma once does the job that include guards used to do, (...)

They don't. They are not C++ and at most they are compiler-specific.

It's fine if you opt to not write C++ and instead target specific compilers instead. Just don't pretend it's not frowned upon or kosher.

replies(2): >>44524966 #>>44526854 #
2. bogwog ◴[] No.44524966[source]
TIL about the existence of a passionate #pragma once hating subculture.

Since you seem to be more knowledgeble about this, I'm curious to know which C++ compilers lack support? I know that at least the 3 big ones do (GCC, Clang, and MSVC) and they have for a very long time.

3. jcelerier ◴[] No.44526854[source]
it's absolutely not frowned upon in 2025. All the compilers that matter (GCC, Clang and MSVC) support and have supported them for two decades. Major projects use #pragma once internally - I see files using it in Qt, LLVM, etc.