FSM_INITIAL_STATE Macro only works in global namespace
- Dominant language
- C++
- Stars
- 1.2k
- Forks
- 193
- PR merge metrics
- No merged PRs in 30d
Description
I observed that the macro `FSM_INITIAL_STATE` doesn't compile if invoked outside of the global namespace. The examples I looked at all use the global namespace so it isn't clear to me if much though was given to namespaces by the author.
example code that wont compile:
```
#include
namespace xxx::yyy {
// ----------------------------------------------------------------------------
// 1. Event Declarations
//
struct AAA : tinyfsm::Event { };
struct BBB : tinyfsm::Event { };
// ----------------------------------------------------------------------------
// 2. State Machine Base Class Declaration
//
struct SM : tinyfsm::MealyMachine
{
virtual void react(AAA const &) { };
virtual void react(BBB const &) { };
};
// ----------------------------------------------------------------------------
// 3. State Declarations
//
struct Wait : SM
{};
struct Off : SM
{};
FSM_INITIAL_STATE(SM, Off)
} // namespace xxx::yyy
```
Solution is to use the macro in the global namespace and fully qualify the state machine and state types:
```
#include
namespace xxx::yyy {
// ----------------------------------------------------------------------------
// 1. Event Declarations
//
struct AAA : tinyfsm::Event { };
struct BBB : tinyfsm::Event { };
// ----------------------------------------------------------------------------
// 2. State Machine Base Class Declaration
//
struct SM : tinyfsm::MealyMachine
{
virtual void react(AAA const &) { };
virtual void react(BBB const &) { };
};
// ----------------------------------------------------------------------------
// 3. State Declarations
//
struct Wait : SM
{
};
struct Off : SM
{
};
} // namespace xxx::yyy
FSM_INITIAL_STATE(xxx::yyy::SM, xxx::yyy::Off)
```
Is it possible to rework FSM_INITIAL_STATE to allow invocation within a custom namespace?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.