1 #include <boost/coroutine/all.hpp> 2 3 #include <cstdlib> 4 #include <iostream> 5 6 #include <boost/bind.hpp> 7 8 #include "X.h" 9 10 typedef boost::coroutines::asymmetric_coroutine< X& >::pull_type pull_coro_t; 11 typedef boost::coroutines::asymmetric_coroutine< X& >::push_type push_coro_t; 12 fn1(push_coro_t & sink)13void fn1( push_coro_t & sink) 14 { 15 for ( int i = 0; i < 10; ++i) 16 { 17 X x( i); 18 sink( x); 19 } 20 } 21 fn2(pull_coro_t & source)22void fn2( pull_coro_t & source) 23 { 24 while ( source) { 25 X & x = source.get(); 26 std::cout << "i = " << x.i << std::endl; 27 source(); 28 } 29 } 30 main(int argc,char * argv[])31int main( int argc, char * argv[]) 32 { 33 { 34 pull_coro_t source( fn1); 35 while ( source) { 36 X & x = source.get(); 37 std::cout << "i = " << x.i << std::endl; 38 source(); 39 } 40 } 41 { 42 push_coro_t sink( fn2); 43 for ( int i = 0; i < 10; ++i) 44 { 45 X x( i); 46 sink( x); 47 } 48 } 49 std::cout << "Done" << std::endl; 50 51 return EXIT_SUCCESS; 52 } 53 54