gpt4 book ai didi

c++ - 无法使用boost::asio::yield_context编译boost::asio::spawn程序

转载 作者:行者123 更新时间:2023-12-02 10:26:48 46 4
gpt4 key购买 nike

我想使用boost::asio从多个stdout中同时读取stderrboost::process。但是,我在使用boost::asio时遇到了编译问题,可以重建以下无法编译的最小示例:

#include <boost/asio.hpp>
#include <boost/asio/spawn.hpp>

int main() {
boost::asio::io_context ios;
boost::asio::spawn(ios,
[](boost::asio::yield_context ctx) {
});
ios.run();
return 0;
}
启用 10.2.0并链接到 C++17版本 boost的GCC 1.72结果如下:
In file included from /usr/include/boost/coroutine/coroutine.hpp:10,
from /usr/include/boost/coroutine/all.hpp:11,
from /usr/include/boost/asio/spawn.hpp:19,
from [...]/main.cpp:3:
/usr/include/boost/coroutine/asymmetric_coroutine.hpp: In function ‘typename boost::coroutines::pull_coroutine<R>::iterator boost::coroutines::begin(boost::coroutines::pull_coroutine<Arg>&)’
/usr/include/boost/coroutine/asymmetric_coroutine.hpp:2364:17: error: ‘begin’ is not a member of ‘boost’
2364 | { return boost::begin( c); }

最佳答案

是的,这是特定版本的Boost中缺少的间接包含。看到它live on wandbox
要么

  • 升级以提升1.73,live
  • 包括相关的标题also live:

  • #include <boost/asio.hpp>
    #include <boost/range/begin.hpp>
    #include <boost/range/end.hpp>
    #include <boost/asio/spawn.hpp>

    int main() {
    boost::asio::io_context ios;
    boost::asio::spawn(ios,
    [](boost::asio::yield_context ctx) {
    });
    ios.run();
    return 0;
    }

    关于c++ - 无法使用boost::asio::yield_context编译boost::asio::spawn程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64092635/

    46 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com