boost-ext::sml 不会编译访问者示例

问题描述 投票:0回答:1

我正在尝试从源代码编译并尝试

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++ boost boost-sml
1个回答
0
投票

不需要 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 模式编译。

© www.soinside.com 2019 - 2024. All rights reserved.