News for hackers. Stuff that matters.
Re:The Two Factions of C++ by quietbritishjim on Monday November 25, 2024 @05:00AM (#42234800)
State machines don't have a native syntax in C++ at all, so you can structure them however you want. It's easy to structure a state machine, if needed, so that all (or some) states can handle the same event in the same way.
Re:The Two Factions of C++ by dgfitz on Monday November 25, 2024 @10:04AM (#42236855)
I always thought this framework was neat: https://doc.qt.io/qt-5/statemachine-api.html

Downside of course is now you have a dependency on qt.

Re:The Two Factions of C++ by alexvitkov on Monday November 25, 2024 @12:38PM (#42238226)
The downside is that you're now heap allocating at least one object for every state, and I'm willing to bet that each QState has an associated std::vector-style list of actions, and that each action is also its own object on the heap.

If you can afford to do things like this you can most likely use something other than C++ and save yourself a lot of headaches.

Re:The Two Factions of C++ by dgfitz on Monday November 25, 2024 @12:53PM (#42238374)
> If you can afford to do things like this you can most likely use something other than C++ and save yourself a lot of headaches.

Surely you can understand that, despite the recent c++ hate, my job doesn't give a fuck and we aren't migrating our massive codebase from c++ to... anything.

Re:The Two Factions of C++ by garethrowlands on Monday November 25, 2024 @02:37PM (#42239419)
Switch + goto is very close to being a native syntax for state machines. It's also very efficient.