-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.cpp
56 lines (48 loc) · 960 Bytes
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*********************************************************
File Name: main.cpp
Author: Abby Cin
Mail: abbytsing@gmail.com
Created Time: Sun 03 Jun 2018 10:24:50 AM CST
**********************************************************/
#include <string>
#include <iostream>
#include "coroutine.h"
void foo(nm::Coroutine<char> *co, const std::string &str)
{
for (auto &c : str) {
printf("%c", c);
co->yield();
}
printf("\n");
}
int main()
{
{
nm::Coroutine<char> co;
co.start(foo, &co, "hello world");
for (auto iter = co.begin(); iter != co.end(); ++iter) {
}
}
{
nm::Coroutine<int> co;
co.start(
[&co](int x)
{
int first = 1;
co.yield(first);
int second = 1;
co.yield(second);
for (int i = 0; i < x; ++i) {
int third = first + second;
first = second;
second = third;
co.yield(third);
}
},
10);
for (auto &iter : co) {
printf("%d ", iter);
}
printf("\n");
}
}