14 #include <string_view>
101 template <
typename Derived,
typename... States>
108 constexpr
static std::string_view
name =
"Terminated";
124 : m_state(typename std::tuple_element<0, std::
tuple<States...>>::
type{}) {
133 const StateVariant& getState() const noexcept {
return m_state; }
142 template <
typename State,
typename...
Args>
144 Derived&
child =
static_cast<Derived&
>(*this);
147 std::visit([&](
auto&
s) { child.on_exit(
s, std::forward<Args>(
args)...); },
153 child.on_enter(std::get<State>(m_state), std::forward<Args>(
args)...);
160 template <
typename S>
161 bool is(
const S& state)
const noexcept {
170 template <
typename S>
171 bool is() const noexcept {
172 if (std::get_if<S>(&m_state)) {
180 bool terminated() const noexcept {
return is<Terminated>(); }
191 template <
typename Event,
typename...
Args>
193 Derived& child =
static_cast<Derived&
>(*this);
195 child.on_process(
event);
197 auto new_state = std::visit(
198 [&](
auto&
s) -> std::optional<StateVariant> {
199 auto s2 = child.on_event(
s, std::forward<Event>(
event),
200 std::forward<Args>(
args)...);
203 std::visit([&](
auto& s2_) { child.on_process(
s,
event, s2_); },
206 child.on_process(
s,
event);
221 template <
typename Event,
typename...
Args>