12 #include <string_view>
101 template <
typename Derived,
typename... States>
108 constexpr
static std::string_view
name =
"Terminated";
125 typename std::tuple_element<0, std::tuple<States...>>::type{}){};
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& ) const noexcept {
169 template <
typename S>
170 bool is() const noexcept {
171 if (std::get_if<S>(&
m_state)) {
179 bool terminated() const noexcept {
return is<Terminated>(); }
190 template <
typename Event,
typename... Args>
192 Derived& child =
static_cast<Derived&
>(*this);
194 child.on_process(event);
196 auto new_state = std::visit(
197 [&](
auto&
s) -> std::optional<StateVariant> {
198 auto s2 = child.on_event(
s, std::forward<Event>(event),
199 std::forward<Args>(args)...);
202 std::visit([&](
auto& s2_) { child.on_process(
s, event, s2_); },
205 child.on_process(
s, event);
207 return std::move(s2);
210 return std::move(new_state);
220 template <
typename Event,
typename... Args>
222 auto new_state =
process_event(std::forward<Event>(event), args...);
225 [&](
auto&
s) {
setState(std::move(
s), std::forward<Args>(args)...); },