首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Boost coroutine不会编译,因为对callcc的调用不明确

Boost coroutine不会编译,因为对callcc的调用不明确
EN

Stack Overflow用户
提问于 2017-06-26 22:19:06
回答 1查看 381关注 0票数 3

我试图在工作中的C++项目中使用协同机制。但是,由于对callcc()的使用不明确,它将不会编译。我尝试在coroutine构造函数中指定分配器,但这似乎没有什么区别。

在将代码剥离到其最基本的基本要素之后,我以非常类似于boost文档中的fibbonacci示例来重现这个问题。

代码语言:javascript
复制
#include <iostream>
#include <boost/coroutine2/all.hpp>

/*
    c++ -std=c++11 -o corofib corofib.cpp
*/

typedef boost::coroutines2::coroutine<unsigned long> coro_t;

coro_t::pull_type generator(
    [](coro_t::push_type& sink) {
        unsigned long first = 1L;
        unsigned long second = 1L;
        unsigned long answer;

        sink(first);
        sink(second);
        while(1) {
            answer = first + second;
            first = second;
            second = answer;
            sink(answer);
        };
    }
);


int main(int argc, char* argv[]) {
    generator();
    std::cout << generator.get() << std::endl;
    generator();
    std::cout << generator.get() << std::endl;
    generator();
    std::cout << generator.get() << std::endl;
    generator();
    std::cout << generator.get() << std::endl;
}

我正在使用:

  • Boost 1.64
  • gcc版4.9.2
  • Linux委托3.16.0-4-AMD 64 #1 SMP Debian 3.16.39-1+GNU 8u 2 (2017-03-07) x86_64 GNU/Linux

这是我收到的错误信息。为了缩短这篇文章,我删除了“必需的”通知:

代码语言:javascript
复制
lear@delegato:~/lamu$ c++ -std=c++14 -o corofib corofib.cpp
In file included from /usr/local/include/boost/coroutine2/detail/coroutine.hpp:48:0,
                 from /usr/local/include/boost/coroutine2/coroutine.hpp:15,
                 from /usr/local/include/boost/coroutine2/all.hpp:10,
                 from corofib.cpp:2:
/usr/local/include/boost/coroutine2/detail/pull_control_block_cc.ipp: In instantiation of ‘boost::coroutines2::detail::pull_coroutine<T>::control_block::control_block(boost::context::preallocated, StackAllocator, Fn&&) [with StackAllocator = boost::context::basic_fixedsize_stack<boost::context::stack_traits>; Fn = <lambda(boost::coroutines2::coroutine<long unsigned int>::push_type&)>; T = long unsigned int]’:
/usr/local/include/boost/coroutine2/detail/pull_control_block_cc.ipp:105:14: error: call of overloaded ‘callcc(const std::allocator_arg_t&, boost::context::preallocated&, boost::context::basic_fixedsize_stack<boost::context::stack_traits>&, boost::coroutines2::detail::pull_coroutine<T>::control_block::control_block(boost::context::preallocated, StackAllocator, Fn&&) [with StackAllocator = boost::context::basic_fixedsize_stack<boost::context::stack_traits>; Fn = <lambda(boost::coroutines2::coroutine<long unsigned int>::push_type&)>; T = long unsigned int]::<lambda(boost::context::continuation&&)>)’ is ambiguous
             });
              ^
/usr/local/include/boost/coroutine2/detail/pull_control_block_cc.ipp:105:14: note: candidates are:
In file included from /usr/local/include/boost/coroutine2/detail/pull_control_block_cc.hpp:14:0,
                 from /usr/local/include/boost/coroutine2/detail/coroutine.hpp:37,
                 from /usr/local/include/boost/coroutine2/coroutine.hpp:15,
                 from /usr/local/include/boost/coroutine2/all.hpp:10,
                 from corofib.cpp:2:
/usr/local/include/boost/context/continuation.hpp:469:1: note: boost::context::continuation boost::context::callcc(std::allocator_arg_t, StackAlloc, Fn&&, Arg ...) [with StackAlloc = boost::context::preallocated; Fn = boost::context::basic_fixedsize_stack<boost::context::stack_traits>&; Arg = {boost::coroutines2::detail::pull_coroutine<T>::control_block::control_block(boost::context::preallocated, StackAllocator, Fn&&) [with StackAllocator = boost::context::basic_fixedsize_stack<boost::context::stack_traits>; Fn = <lambda(boost::coroutines2::coroutine<long unsigned int>::push_type&)>; T = long unsigned int]::<lambda(boost::context::continuation&&)>}]
 callcc( std::allocator_arg_t, StackAlloc salloc, Fn && fn, Arg ... arg) {
 ^
/usr/local/include/boost/context/continuation.hpp:483:1: note: boost::context::continuation boost::context::callcc(std::allocator_arg_t, boost::context::preallocated, StackAlloc, Fn&&, Arg ...) [with StackAlloc = boost::context::basic_fixedsize_stack<boost::context::stack_traits>; Fn = boost::coroutines2::detail::pull_coroutine<T>::control_block::control_block(boost::context::preallocated, StackAllocator, Fn&&) [with StackAllocator = boost::context::basic_fixedsize_stack<boost::context::stack_traits>; Fn = <lambda(boost::coroutines2::coroutine<long unsigned int>::push_type&)>; T = long unsigned int]::<lambda(boost::context::continuation&&)>; Arg = {}]
 callcc( std::allocator_arg_t, preallocated palloc, StackAlloc salloc, Fn && fn, Arg ... arg) {
 ^
/usr/local/include/boost/context/continuation.hpp:514:1: note: boost::context::continuation boost::context::callcc(std::allocator_arg_t, boost::context::preallocated, StackAlloc, Fn&&) [with StackAlloc = boost::context::basic_fixedsize_stack<boost::context::stack_traits>; Fn = boost::coroutines2::detail::pull_coroutine<T>::control_block::control_block(boost::context::preallocated, StackAllocator, Fn&&) [with StackAllocator = boost::context::basic_fixedsize_stack<boost::context::stack_traits>; Fn = <lambda(boost::coroutines2::coroutine<long unsigned int>::push_type&)>; T = long unsigned int]::<lambda(boost::context::continuation&&)>]
 callcc( std::allocator_arg_t, preallocated palloc, StackAlloc salloc, Fn && fn) {
 ^
/usr/local/include/boost/context/continuation.hpp:457:1: note: boost::context::continuation boost::context::callcc(Fn&&, Arg ...) [with Fn = const std::allocator_arg_t&; Arg = {boost::context::preallocated, boost::context::basic_fixedsize_stack<boost::context::stack_traits>, boost::coroutines2::detail::pull_coroutine<T>::control_block::control_block(boost::context::preallocated, StackAllocator, Fn&&) [with StackAllocator = boost::context::basic_fixedsize_stack<boost::context::stack_traits>; Fn = <lambda(boost::coroutines2::coroutine<long unsigned int>::push_type&)>; T = long unsigned int]::<lambda(boost::context::continuation&&)>}; <template-parameter-1-3> = void]
 callcc( Fn && fn, Arg ... arg) {

我认为代码基本上是正确的:我只需要在某种程度上对此进行模糊处理。

我可以说在蟒蛇身上做这件事是多么容易,但这可能会引起笑声。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-06-27 17:14:38

这是Boost.Context中的一个bug,它位于已报告固定上游。您可以找到专门针对Boost 1.64 这里的修补程序。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44769482

复制
相关文章

相似问题

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