我正在使用 boost::coroutine 调用非 void 函数
typedef boost::coroutines::coroutine< int(void) > coro_t;
typedef coro_t::caller_type Yield_target;
myClass* do_something(Yield_target& yield)
{
myClass* m = new myClass;
// ... do smt
yield();
// ... do smt
return m;
}
然后我调用我的函数并将其绑定(bind)到 boost 协程。函数(协程)完成后,如何获取 myClass* 的返回值?
最佳答案
您在问题陈述中提到的类型 coro_t::caller_type 可能已被弃用,因为它未在 more recent Boost Documentation 中列出。 .然而,here在最近的文档中,您可能会在 coroutine<>::push_type 部分看到一个短语,“您无法使用这种协程从另一个执行上下文中检索值”。
虽然我不确定您打算如何使用协程库,但我怀疑您会比coroutine<>::pull_type更频繁地使用coroutine<>::push_type>,所以我猜你需要找到另一种方法来检索返回值,而不是库本身。
关于c++ - boost协程如何在coro_t完成后检索函数返回值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23675272/