• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <boost/coroutine/all.hpp>
2 
3 #include <boost/bind.hpp>
4 
5 #include "X.h"
6 
7 typedef boost::coroutines::asymmetric_coroutine< X& >::pull_type pull_coro_t;
8 typedef boost::coroutines::asymmetric_coroutine< X& >::push_type push_coro_t;
9 
foo1(push_coro_t & sink)10 void foo1( push_coro_t & sink)
11 {
12     for ( int i = 0; i < 10; ++i)
13     {
14         X x( i);
15         sink( x);
16     }
17 }
18 
foo2(pull_coro_t & source)19 void foo2( pull_coro_t & source)
20 {
21     while ( source) {
22         X & x = source.get();
23         source();
24     }
25 }
26 
bar()27 void bar()
28 {
29     {
30         pull_coro_t source( foo1);
31         while ( source) {
32             X & x = source.get();
33             source();
34         }
35     }
36     {
37         push_coro_t sink( foo2);
38         for ( int i = 0; i < 10; ++i)
39         {
40             X x( i);
41             sink( x);
42         }
43     }
44 }
45 
46