libostd/examples/coroutine2.cc

29 lines
416 B
C++
Raw Normal View History

2017-03-06 03:31:37 +01:00
#include <ostd/io.hh>
#include <ostd/coroutine.hh>
using namespace ostd;
int main() {
generator<int> g = [](auto yield) {
yield(5);
yield(10);
yield(15);
yield(20);
2017-03-06 03:31:37 +01:00
return 25;
};
writeln("generator test");
for (int i: g) {
writeln("generated: ", i);
}
}
/*
generator test
generated: 5
generated: 10
generated: 15
generated: 20
generated: 25
*/