首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >促进::asio::产卵是破坏与BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT?

促进::asio::产卵是破坏与BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT?
EN

Stack Overflow用户
提问于 2020-12-02 19:53:47
回答 1查看 637关注 0票数 1

在将boost库从1.71更新到1.74之后,我使用boost::asio::spawn()的代码不使用MSVC2019 (x64为19.25.28612)进行预定义宏BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT的编译。AFAIK,这个宏应该是向后兼容的,我必须使用这个宏,因为我使用了boost::beast::saved_handler,但是它使用了未为建议的标准执行器定义的执行器工作保护。

不仅如此,我的代码成功地使用clang-11 (并定义了BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT)编译。

下面是一个简单的代码示例,它无法使用MSVC2019和Boost.Asio:1.74编译,但将使用Boost.Asio:1.71编译(当然,boost::asio::any_io_executor应该用boost::asio::executor替换):

代码语言:javascript
复制
#define BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT
#include <boost/asio.hpp>
#include <boost/asio/spawn.hpp>

int main()
{
  boost::asio::io_context ctx;
  boost::asio::any_io_executor executor = ctx.get_executor();
  boost::asio::spawn(executor, [](auto yield){});
  return 0;
}

产出如下:

代码语言:javascript
复制
C:\local\boost_1_74_0\boost/asio/execution/execute.hpp(192): error C2672: 'boost::asio::strand<Executor>::execute': no matching overloaded function found
        with
        [
            Executor=boost::asio::executor
        ]
C:\local\boost_1_74_0\boost/asio/impl/dispatch.hpp(57): note: see reference to function template instantiation 'void asio_execution_execute_fn::impl::operator ()<boost::asio::strand<Executor>,boost::asio::detail::spawn_helper<handler_type,function_type>&>(T &&,F) noexcept(false) const' being compiled
        with
        [
            Executor=boost::asio::executor,
            T=boost::asio::strand<boost::asio::executor>,
            F=boost::asio::detail::spawn_helper<handler_type,function_type> &
        ]
C:\local\boost_1_74_0\boost/asio/async_result.hpp(151): note: see reference to function template instantiation 'void boost::asio::detail::initiate_dispatch::operator ()<boost::asio::detail::spawn_helper<handler_type,function_type>&>(CompletionHandler,void *) const' being compiled
        with
        [
            CompletionHandler=boost::asio::detail::spawn_helper<handler_type,function_type> &
        ]
C:\local\boost_1_74_0\boost/asio/async_result.hpp(363): note: see reference to function template instantiation 'boost::asio::async_result<boost::asio::detail::spawn_helper<handler_type,function_type>,Signature>::return_type boost::asio::async_result<boost::asio::detail::spawn_helper<handler_type,function_type>,Signature>::initiate<Initiation,boost::asio::detail::spawn_helper<handler_type,function_type>&,>(Initiation &&,RawCompletionToken)' being compiled
        with
        [
            Signature=void (void),
            Initiation=boost::asio::detail::initiate_dispatch,
            RawCompletionToken=boost::asio::detail::spawn_helper<handler_type,function_type> &
        ]
C:\local\boost_1_74_0\boost/asio/async_result.hpp(364): note: see reference to function template instantiation 'boost::asio::async_result<boost::asio::detail::spawn_helper<handler_type,function_type>,Signature>::return_type boost::asio::async_result<boost::asio::detail::spawn_helper<handler_type,function_type>,Signature>::initiate<Initiation,boost::asio::detail::spawn_helper<handler_type,function_type>&,>(Initiation &&,RawCompletionToken)' being compiled
        with
        [
            Signature=void (void),
            Initiation=boost::asio::detail::initiate_dispatch,
            RawCompletionToken=boost::asio::detail::spawn_helper<handler_type,function_type> &
        ]
C:\local\boost_1_74_0\boost/asio/impl/dispatch.hpp(212): note: see reference to function template instantiation 'void boost::asio::async_initiate<CompletionToken,void(void),boost::asio::detail::initiate_dispatch,>(Initiation &&,CompletionToken)' being compiled
        with
        [
            CompletionToken=boost::asio::detail::spawn_helper<handler_type,function_type> &,
            Initiation=boost::asio::detail::initiate_dispatch
        ]
C:\local\boost_1_74_0\boost/asio/impl/spawn.hpp(452): note: see reference to function template instantiation 'void boost::asio::dispatch<boost::asio::detail::spawn_helper<handler_type,function_type>&>(CompletionToken)' being compiled
        with
        [
            CompletionToken=boost::asio::detail::spawn_helper<handler_type,function_type> &
        ]
C:\local\boost_1_74_0\boost/asio/impl/spawn.hpp(493): note: see reference to function template instantiation 'void boost::asio::spawn<boost::asio::executor_binder<void (__cdecl *)(void),boost::asio::strand<Executor>>,Function>(Handler &&,Function &&,const boost::coroutines::attributes &,void *)' being compiled
        with
        [
            Executor=boost::asio::executor,
            Function=main::<lambda_c142a977195366454fba7e579637857b>,
            Handler=boost::asio::executor_binder<void (__cdecl *)(void),boost::asio::strand<boost::asio::executor>>
        ]
C:\local\boost_1_74_0\boost/asio/impl/spawn.hpp(483): note: see reference to function template instantiation 'void boost::asio::spawn<Function,Executor>(const boost::asio::strand<Executor> &,Function &&,const boost::coroutines::attributes &)' being compiled
        with
        [
            Function=main::<lambda_c142a977195366454fba7e579637857b>,
            Executor=boost::asio::executor
        ]
C:\Users\Artem Suleimanov\CLionProjects\test\main.cpp(10): note: see reference to function template instantiation 'void boost::asio::spawn<main::<lambda_c142a977195366454fba7e579637857b>,boost::asio::executor>(const Executor &,Function &&,const boost::coroutines::attributes &,void *)' being compiled
        with
        [
            Executor=boost::asio::executor,
            Function=main::<lambda_c142a977195366454fba7e579637857b>
        ]
C:\local\boost_1_74_0\boost/asio/execution/execute.hpp(192): error C2893: Failed to specialize function template 'enable_if<boost::asio::execution::can_execute<const Executor&,Function>::value,void>::type boost::asio::strand<Executor>::execute(Function &&) const'
        with
        [
            Executor=boost::asio::executor
        ]
C:\local\boost_1_74_0\boost/asio/strand.hpp(276): note: see declaration of 'boost::asio::strand<Executor>::execute'
        with
        [
            Executor=boost::asio::executor
        ]
C:\local\boost_1_74_0\boost/asio/execution/execute.hpp(192): note: With the following template arguments:
C:\local\boost_1_74_0\boost/asio/execution/execute.hpp(192): note: 'Function=boost::asio::detail::spawn_helper<handler_type,function_type> &'

那是编译器/boost bug,还是我做错了什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-12-03 18:36:28

看来这个问题是固定的。我应用了现在由MSVC2019编译的修补程序和代码。

此修补程序的THe发布说明条目:

  • 修正了针对较旧的strand<>版本或不太符合C++的编译器时网络TS执行器的C++适配。
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65115207

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档