#include <functional>
#include <iostream>
#include <boost/coroutine/all.hpp>
using boost::coroutines::coroutine;
void cooperative(coroutine<int>::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<int>::pull_type source{ std::bind(cooperative, _1, 0) };
std::cout << source.get() << '\n';
//调用cooperative
source();
std::cout << source.get() << '\n';
//调用cooperative
source();
}
c++协程2 (boost::coroutine)
最新推荐文章于 2024-08-01 15:35:29 发布