Boost coroutine won't compile because of an ambiguous callcc call
I am trying to use coroutines in a C ++ project. However, it won't compile due to ambiguous usage callcc()
. I tried specifying the allocators in the coprocessor constructor, but that doesn't seem to make a difference.
After we compiled the code to its bare essentials, I ended up reproducing the problem with something very similar to the fibonacci examples from the acceleration documentation.
#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;
}
I use:
- Boost 1.64
- gcc version 4.9.2
- Linux delegato 3.16.0-4-amd64 # 1 SMP Debian 3.16.39-1 + deb8u2 (2017-03-07) x86_64 GNU / Linux
Here are the error messages I get. I removed the "must-out" notices in an attempt to shorten this message:
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) {
I think the code basically sounds like: I just need to fix this somehow.
I could say something about how easy it is to do this in python, but it might make you laugh.
+3
source to share