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)
7 #include <boost/coroutine/all.hpp>
14 #include <boost/bind.hpp>
15 #include <boost/throw_exception.hpp>
17 typedef boost::coroutines::asymmetric_coroutine< int >::pull_type pull_coro_t;
18 typedef boost::coroutines::asymmetric_coroutine< int >::push_type push_coro_t;
20 struct my_exception : public std::runtime_error
22 my_exception( std::string const& str) :
23 std::runtime_error( str)
27 void echo( push_coro_t & sink, int j)
29 for ( int i = 0; i < j; ++i)
31 if ( i == 5) boost::throw_exception( my_exception("abc") );
36 int main( int argc, char * argv[])
38 pull_coro_t source( boost::bind( echo, _1, 10) );
43 std::cout << source.get() << std::endl;
47 catch ( my_exception const& ex)
48 { std::cout << "exception: " << ex.what() << std::endl; }
50 std::cout << "\nDone" << std::endl;