Boost 协程由于对 callcc 的不明确调用而无法编译
Boost coroutine won't compile because of ambiguous call to callcc
我正在尝试在工作中的C 项目中使用Coroutines。但是,由于callcc()
的模棱两可,它不会编译。我尝试在Coroutine构造器中指定分配器,但这似乎并没有差异。
将代码删除到其最少的必需品后,我最终以与Boost文档中的fibbonacci示例相似的内容重现了问题。
#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
这是我收到的错误消息。我已经删除了"要求"通知,以缩短这篇文章:
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中的一个错误,已报告并在上游修复。您可以在此处找到专门针对Boost 1.64的补丁。
相关文章:
- C++ 编译器错误:P1LinkedList.cpp:145:错误:重载的"to_string(int&)"调用不明确
- 为什么调用不明确的 ctor 时没有编译时错误?
- G++ 错误:重载的"abs(无符号 int)"的调用不明确
- 如果存在具有不同参数的继承成员,为什么对 C++ 结构函数的调用不明确?
- 错误:重载'stoi(nlohmann::basic_json<>::value_type&)'的调用不明确
- 构建 castalia 时出错:重载函数的调用不明确
- 错误:重载的"abs(double)"调用不明确
- 结构构造函数调用不明确
- 错误:对重载函数的调用不明确
- 对重载'swap(char&, char&)'的调用不明确
- 对可变模板函数的调用不明确
- C++ 编译错误:重载的"<function_name>(char*&)"调用不明确
- VS2010中具有list_of的调用不明确
- 为什么这个运算符=调用不明确
- 为什么对重载函数的调用不明确
- C++中重载运算符函数对构造函数的调用不明确
- 为什么这些重载函数调用不明确
- 重载write(int)的调用不明确
- 带有重载r值引用函数的调用不明确
- 传递0而不是1时,sfinae调用不明确