gpt4 book ai didi

c++ - 由于对 callcc 的调用不明确,Boost 协程无法编译

转载 作者:太空狗 更新时间:2023-10-29 22:57:19 25 4
gpt4 key购买 nike

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

在将代码剥离到最基本的部分后,我最终用与 boost 文档中的斐波那契示例非常相似的东西重现了这个问题。

#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 delegato 3.16.0-4-amd64 #1 SMPDebian 3.16.39-1+deb8u2 (2017-03-07) x86_64 GNU/Linux

这是我收到的错误消息。我已经删除了“required from”通知以试图缩短这篇文章:

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) {

我认为代码基本上是合理的:我只需要以某种方式消除歧义。

我可以说说这在 python 中是多么容易,但它可能会引起笑声。

最佳答案

这是 Boost.Context 中的一个错误,它是 reportedfixed上游的。您可以找到专门针对 Boost 1.64 的补丁 here .

关于c++ - 由于对 callcc 的调用不明确,Boost 协程无法编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44769482/

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