1 2 // Copyright Oliver Kowalke 2009. 3 // Distributed under the Boost Software License, Version 1.0. 4 // (See accompanying file LICENSE_1_0.txt or copy at 5 // http://www.boost.org/LICENSE_1_0.txt) 6 7 #include <cstdlib> 8 #include <iostream> 9 10 #include <boost/bind.hpp> 11 #include <boost/coroutine/all.hpp> 12 13 typedef boost::coroutines::asymmetric_coroutine< void >::pull_type pull_coro_t; 14 typedef boost::coroutines::asymmetric_coroutine< void >::push_type push_coro_t; 15 echo(pull_coro_t & source,int i)16void echo( pull_coro_t & source, int i) 17 { 18 std::cout << i; 19 source(); 20 } 21 runit(push_coro_t & sink1)22void runit( push_coro_t & sink1) 23 { 24 std::cout << "started! "; 25 for ( int i = 0; i < 10; ++i) 26 { 27 push_coro_t sink2( boost::bind( echo, _1, i) ); 28 while ( sink2) 29 sink2(); 30 sink1(); 31 } 32 } 33 main(int argc,char * argv[])34int main( int argc, char * argv[]) 35 { 36 { 37 pull_coro_t source( runit); 38 while ( source) { 39 std::cout << "-"; 40 source(); 41 } 42 } 43 44 std::cout << "\nDone" << std::endl; 45 46 return EXIT_SUCCESS; 47 } 48