#include <tuple>
#include <string>
#include <iostream>
#include <boost/coroutine/all.hpp>
using boost::coroutines::coroutine;
void cooperative(coroutine<std::tuple<int, std::string>>::pull_type &source)
{
auto args = source.get();
std::cout << std::get<0>(args) << " " << std::get<1>(args) << '\n';
source();
args = source.get();
std::cout << std::get<0>(args) << " " << std::get<1>(args) << '\n';
}
int main()
{
coroutine<std::tuple<int, std::string>>::push_type sink{ cooperative };
//通过tuple传递多个参数
sink(std::make_tuple(0, "aaa"));
//通过tuple传递多个参数
sink(std::make_tuple(1, "bbb"));
std::cout << "end\n";
}
c++协程3 (boost::coroutine)
最新推荐文章于 2025-01-07 20:34:54 发布