SML2: A C++20 State Machine Library with Self-Testing at Compile-Time
The article introduces SML2, a C++20 state machine library that fully tests itself at compile-time upon use. The library is based on the UML-2.5 State Machine Language and aims to make the application flow easier to understand and maintain. By making the state explicit, SML2 helps developers avoid spaghetti code and provides a clearer structure for their programs. While switch-case and state pattern can be used as alternatives, the article argues that the long-term maintenance of such solutions becomes more complex over time. SML2 currently supports basic UML features such as transitions, processing events, and unexpected events, with plans to add more features in the future. One notable feature of SML2 is its self-testing capability, which allows all tests to be executed at compile-time when the library is included or imported. This approach provides additional guarantees and ensures that the tested features work as expected. Developers can find tests and examples on the library's GitHub repository to stay up to date with its available features.