本文共 485 字,大约阅读时间需要 1 分钟。
#include#include #include using boost::coroutines::coroutine;void cooperative(coroutine ::push_type &sink, int i){ int j = i; //调用main sink(++j); //调用main sink(++j); std::cout << "end\n";}int main(){ using std::placeholders::_1; //传入一个参数,初始值为0 coroutine ::pull_type source{ std::bind(cooperative, _1, 0) }; std::cout << source.get() << '\n'; //调用cooperative source(); std::cout << source.get() << '\n'; //调用cooperative source();}