#include <queue>
#include <memory>
#include "boost/coroutine2/coroutine.hpp"
typedef boost::coroutines2::coroutine<int> coro_t;
int main() {
int l = 0;
std::queue<int> y({1,2,3,4});
std::queue<std::unique_ptr<int>> w;
coro_t::push_type sink([&](coro_t::pull_type& source) {
for (const auto& i : source) {
while (!w.empty()) {
auto ptr = std::move(w.front());
w.pop();
if (*ptr == 1) {
std::cout << "first: " << i << std::endl;
auto item = 21;
w.push(std::move(std::make_unique<int>(item)));
}
else
if (*ptr == 21) {
std::cout << "second: " << i+2*i << std::endl;
auto item = 32;
w.push(std::move(std::make_unique<int>(item)));
}
else
if (*ptr == 32) {
std::cout << "third: " << i*i << std::endl;
}
}
}
source();
});
while (!y.empty()) {
if (!y.empty()) {
l = y.front();
y.pop();
w.push(std::move(std::make_unique<int>(1)));
sink(l);
}
}
return 0;
}