boost-ext::sml 不会编译访问者示例
boost-ext::sml will not compile visitor example
我正在尝试从源代码编译并试验 boost::sml
中的示例。特别是访问者示例将无法编译,因此我的 sml
应用程序缺少一种简单的方法来仅说明其状态机所在的状态。
我 运行 在一台机器上进行初始 cmake 设置时具有以下状态:
-- The CXX compiler identification is GNU 7.5.0
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Performing Test HAS_CXX14_FLAG
-- Performing Test HAS_CXX14_FLAG - Success
-- Performing Test HAS_CXX17_FLAG
-- Performing Test HAS_CXX17_FLAG - Success
-- Performing Test HAS_CXX20_FLAG
-- Performing Test HAS_CXX20_FLAG - Failed
-- Boost version: 1.65.1
-- Configuring done
-- Generating done
大部分代码都能编译,但对于 example/visitor.cpp
,我得到这些错误:
In file included from /data/sml/example/visitor.cpp:8:0:
/data/sml/include/boost/sml.hpp: In instantiation of ‘struct boost::ext::sml::v1_1_4::back::sm_impl<boost::ext::sml::v1_1_4::back::sm_policy<state_name_visitor<boost::ext::sml::v1_1_4::back::sm<boost::ext::sml::v1_1_4::back::sm_policy<composite> > > > >’:
/data/sml/include/boost/sml.hpp:1789:72: required from ‘boost::ext::sml::v1_1_4::back::sm< <template-parameter-1-1> >::operator T&() [with T = state_name_visitor<boost::ext::sml::v1_1_4::back::sm<boost::ext::sml::v1_1_4::back::sm_policy<composite> > >; TSM = boost::ext::sml::v1_1_4::back::sm_policy<composite>]’
/data/sml/example/visitor.cpp:68:62: required from here
/data/sml/include/boost/sml.hpp:1362:68: error: no matching function for call to ‘state_name_visitor<boost::ext::sml::v1_1_4::back::sm<boost::ext::sml::v1_1_4::back::sm_policy<composite> > >::operator()()’
compilation terminated due to -Wfatal-errors.
有什么建议吗?是否需要 C++20?
C++20 不是必需的。 Github 的当前修订包含:
#error "[Boost::ext].SML requires C++14 support (Clang-3.4+, GCC-5.1+, MSVC-2015+)"
事实上,即使在我的 Ubuntu 18.04 盒子上使用 GCC 7.5,它也可以很好地编译 -std=c++14。
但是,由于您的 CMake 输出表明选择了 C++17,因此我尝试了,但出现了同样的问题。我可能会尝试找到解决方法(晚饭后)
更新
我不能说我完全理解这一点,但以下更改使其有效:
const auto state_name = state_name_visitor<decltype(sm)>{sm};
应该是
const auto state_name = state_name_visitor<decltype((sm))>{sm};
或者
const auto state_name = state_name_visitor<decltype(sm)&>{sm};
现在它可以在 GCC 7.5 上以 C++17 模式编译。
我正在尝试从源代码编译并试验 boost::sml
中的示例。特别是访问者示例将无法编译,因此我的 sml
应用程序缺少一种简单的方法来仅说明其状态机所在的状态。
我 运行 在一台机器上进行初始 cmake 设置时具有以下状态:
-- The CXX compiler identification is GNU 7.5.0
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Performing Test HAS_CXX14_FLAG
-- Performing Test HAS_CXX14_FLAG - Success
-- Performing Test HAS_CXX17_FLAG
-- Performing Test HAS_CXX17_FLAG - Success
-- Performing Test HAS_CXX20_FLAG
-- Performing Test HAS_CXX20_FLAG - Failed
-- Boost version: 1.65.1
-- Configuring done
-- Generating done
大部分代码都能编译,但对于 example/visitor.cpp
,我得到这些错误:
In file included from /data/sml/example/visitor.cpp:8:0:
/data/sml/include/boost/sml.hpp: In instantiation of ‘struct boost::ext::sml::v1_1_4::back::sm_impl<boost::ext::sml::v1_1_4::back::sm_policy<state_name_visitor<boost::ext::sml::v1_1_4::back::sm<boost::ext::sml::v1_1_4::back::sm_policy<composite> > > > >’:
/data/sml/include/boost/sml.hpp:1789:72: required from ‘boost::ext::sml::v1_1_4::back::sm< <template-parameter-1-1> >::operator T&() [with T = state_name_visitor<boost::ext::sml::v1_1_4::back::sm<boost::ext::sml::v1_1_4::back::sm_policy<composite> > >; TSM = boost::ext::sml::v1_1_4::back::sm_policy<composite>]’
/data/sml/example/visitor.cpp:68:62: required from here
/data/sml/include/boost/sml.hpp:1362:68: error: no matching function for call to ‘state_name_visitor<boost::ext::sml::v1_1_4::back::sm<boost::ext::sml::v1_1_4::back::sm_policy<composite> > >::operator()()’
compilation terminated due to -Wfatal-errors.
有什么建议吗?是否需要 C++20?
C++20 不是必需的。 Github 的当前修订包含:
#error "[Boost::ext].SML requires C++14 support (Clang-3.4+, GCC-5.1+, MSVC-2015+)"
事实上,即使在我的 Ubuntu 18.04 盒子上使用 GCC 7.5,它也可以很好地编译 -std=c++14。
但是,由于您的 CMake 输出表明选择了 C++17,因此我尝试了,但出现了同样的问题。我可能会尝试找到解决方法(晚饭后)
更新
我不能说我完全理解这一点,但以下更改使其有效:
const auto state_name = state_name_visitor<decltype(sm)>{sm};
应该是
const auto state_name = state_name_visitor<decltype((sm))>{sm};
或者
const auto state_name = state_name_visitor<decltype(sm)&>{sm};
现在它可以在 GCC 7.5 上以 C++17 模式编译。