【发布时间】:2021-01-21 06:10:55
【问题描述】:
我正在使用 SML (https://boost-ext.github.io/sml/) v.1.1.3,我需要访问注入的依赖项和操作中的状态机。 根据以下提交,这应该已经可以工作了:https://github.com/boost-ext/sml/commit/e6d0685993a8a0160dde1610d7f8be4f811c89d0 此提交是此问题的结果: https://github.com/boost-ext/sml/issues/94
在接下来的示例中,我尝试访问 action2 中的依赖项和 sm,但出现编译错误:
...
sml.hpp:1853:18:注意:无法转换 'deps'(类型 'boost::ext::sml::v1_1_3::aux::pool
例子:
#include <boost/sml.hpp>
#include <cassert>
#include <iostream>
namespace sml = boost::sml;
namespace {
struct e1 {};
struct e2 {};
struct e3 {};
auto action2 = [](const auto& event, auto& sm, int& i, std::string& str) {
assert(42 == i);
std::cout << "action2" << std::endl;
std::cout << "sm.n: " << sm.n << std::endl;
};
struct actions_guards {
using self = actions_guards;
int n = 10;
auto operator()() {
using namespace sml;
auto action1 = [](auto e) { std::cout << "action1: " << typeid(e).name() << std::endl; };
auto guard1 = [](int i) {
assert(42 == i);
std::cout << "guard2" << std::endl;
return false;
};
return make_transition_table(
// Start Event Guard Action Next
//+-------------+-------------------+---------------------------+-------------------------------+-------------------------------+
*"idle"_s + event<e1> [ guard1 ] / action1 = "s1"_s,
"s1"_s + event<e2> [ &self::guard2 ] / action2 = "s2"_s,
"s2"_s + event<e3> = X
);
}
bool guard2(int i) const noexcept {
assert(42 == i);
std::cout << "guard3" << std::endl;
return true;
}
};
} // namespace
int main( int argc, char* argv[] )
{
actions_guards ag{};
std::string strDep( "127.0.0.1" );
int intDep = 42;
sml::sm<actions_guards> sm{ag, intDep, strDep};
sm.process_event(e1{});
sm.process_event(e2{});
sm.process_event(e3{});
assert(sm.is(sml::X));
return 0;
}
错误:
...
sml.hpp:1340:10: 来自 'bool boost::ext::sml::v1_1_3::back::sm_impl::process_event(const TEvent&, TDeps&, TSubs&) [with TEvent = {anonymous}:: e2; TDeps = boost::ext::sml::v1_1_3::aux::pool
【问题讨论】:
标签: c++ boost c++14 state-machine boost-extension