coroutine: intro of coroutine<>::pull_type, coroutine<>::push_type

[SVN r85058]
This commit is contained in:
Oliver Kowalke
2013-07-17 14:09:07 +00:00
parent c39d9509a4
commit 865902f9b5
22 changed files with 397 additions and 487 deletions

View File

@@ -57,7 +57,7 @@ public:
state( true)
{}
void operator()( coro::push_coroutine< int > &)
void operator()( coro::coroutine< int >::push_type &)
{ value3 = state; }
};
@@ -89,32 +89,32 @@ public:
return * this;
}
void operator()( coro::push_coroutine< int > &)
void operator()( coro::coroutine< int >::push_type &)
{ value3 = state; }
};
struct my_exception {};
void f1( coro::push_coroutine< void > & c)
void f1( coro::coroutine< void >::push_type & c)
{ c(); }
void f2( coro::push_coroutine< void > &)
void f2( coro::coroutine< void >::push_type &)
{ ++value1; }
void f3( coro::push_coroutine< void > & c)
void f3( coro::coroutine< void >::push_type & c)
{
++value1;
c();
++value1;
}
void f4( coro::push_coroutine< int > & c)
void f4( coro::coroutine< int >::push_type & c)
{
c( 3);
c( 7);
}
void f5( coro::push_coroutine< std::string > & c)
void f5( coro::coroutine< std::string >::push_type & c)
{
std::string res("abc");
c( res);
@@ -122,13 +122,13 @@ void f5( coro::push_coroutine< std::string > & c)
c( res);
}
void f6( coro::pull_coroutine< int > & c)
void f6( coro::coroutine< int >::pull_type & c)
{ value1 = c.get(); }
void f7( coro::pull_coroutine< std::string > & c)
void f7( coro::coroutine< std::string >::pull_type & c)
{ value2 = c.get(); }
void f8( coro::pull_coroutine< boost::tuple< double, double > > & c)
void f8( coro::coroutine< boost::tuple< double, double > >::pull_type & c)
{
double x = 0, y = 0;
boost::tie( x, y) = c.get();
@@ -138,30 +138,30 @@ void f8( coro::pull_coroutine< boost::tuple< double, double > > & c)
value4 = x + y;
}
void f9( coro::pull_coroutine< int * > & c)
void f9( coro::coroutine< int * >::pull_type & c)
{ value5 = c.get(); }
void f91( coro::pull_coroutine< int const* > & c)
void f91( coro::coroutine< int const* >::pull_type & c)
{ value5 = const_cast< int * >( c.get() ); }
void f10( coro::pull_coroutine< int & > & c)
void f10( coro::coroutine< int & >::pull_type & c)
{
int const& i = c.get();
value5 = const_cast< int * >( & i);
}
void f101( coro::pull_coroutine< int const& > & c)
void f101( coro::coroutine< int const& >::pull_type & c)
{
int const& i = c.get();
value5 = const_cast< int * >( & i);
}
void f11( coro::pull_coroutine< boost::tuple< int, int > > & c)
void f11( coro::coroutine< boost::tuple< int, int > >::pull_type & c)
{
boost::tie( value8, value9) = c.get();
}
void f12( coro::pull_coroutine< void > & c)
void f12( coro::coroutine< void >::pull_type & c)
{
X x_;
c();
@@ -169,10 +169,10 @@ void f12( coro::pull_coroutine< void > & c)
}
template< typename E >
void f14( coro::pull_coroutine< void > &, E const& e)
void f14( coro::coroutine< void >::pull_type &, E const& e)
{ throw e; }
void f16( coro::push_coroutine< int > & c)
void f16( coro::coroutine< int >::push_type & c)
{
c( 1);
c( 2);
@@ -181,7 +181,7 @@ void f16( coro::push_coroutine< int > & c)
c( 5);
}
void f17( coro::pull_coroutine< int > & c, std::vector< int > & vec)
void f17( coro::coroutine< int >::pull_type & c, std::vector< int > & vec)
{
int x = c.get();
while ( 5 > x)
@@ -191,7 +191,7 @@ void f17( coro::pull_coroutine< int > & c, std::vector< int > & vec)
}
}
void f19( coro::push_coroutine< const int* > & c, std::vector< const int * > & vec)
void f19( coro::coroutine< const int* >::push_type & c, std::vector< const int * > & vec)
{
BOOST_FOREACH( const int * ptr, vec)
{ c( ptr); }
@@ -200,8 +200,8 @@ void f19( coro::push_coroutine< const int* > & c, std::vector< const int * > & v
void test_move()
{
{
coro::pull_coroutine< void > coro1;
coro::pull_coroutine< void > coro2( f1);
coro::coroutine< void >::pull_type coro1;
coro::coroutine< void >::pull_type coro2( f1);
BOOST_CHECK( ! coro1);
BOOST_CHECK( coro1.empty() );
BOOST_CHECK( coro2);
@@ -218,7 +218,7 @@ void test_move()
copyable cp( 3);
BOOST_CHECK( cp.state);
BOOST_CHECK( ! value3);
coro::pull_coroutine< int > coro( cp);
coro::coroutine< int >::pull_type coro( cp);
BOOST_CHECK( cp.state);
BOOST_CHECK( value3);
}
@@ -228,7 +228,7 @@ void test_move()
moveable mv( 7);
BOOST_CHECK( mv.state);
BOOST_CHECK( ! value3);
coro::pull_coroutine< int > coro( boost::move( mv) );
coro::coroutine< int >::pull_type coro( boost::move( mv) );
BOOST_CHECK( ! mv.state);
BOOST_CHECK( value3);
}
@@ -238,7 +238,7 @@ void test_complete()
{
value1 = 0;
coro::pull_coroutine< void > coro( f2);
coro::coroutine< void >::pull_type coro( f2);
BOOST_CHECK( ! coro);
BOOST_CHECK_EQUAL( ( int)1, value1);
}
@@ -247,7 +247,7 @@ void test_jump()
{
value1 = 0;
coro::pull_coroutine< void > coro( f3);
coro::coroutine< void >::pull_type coro( f3);
BOOST_CHECK( coro);
BOOST_CHECK_EQUAL( ( int)1, value1);
coro();
@@ -257,7 +257,7 @@ void test_jump()
void test_result_int()
{
coro::pull_coroutine< int > coro( f4);
coro::coroutine< int >::pull_type coro( f4);
BOOST_CHECK( coro);
int result = coro.get();
BOOST_CHECK( coro);
@@ -271,7 +271,7 @@ void test_result_int()
void test_result_string()
{
coro::pull_coroutine< std::string > coro( f5);
coro::coroutine< std::string >::pull_type coro( f5);
BOOST_CHECK( coro);
std::string result = coro.get();
BOOST_CHECK( coro);
@@ -287,7 +287,7 @@ void test_arg_int()
{
value1 = 0;
coro::push_coroutine< int > coro( f6);
coro::coroutine< int >::push_type coro( f6);
BOOST_CHECK( coro);
coro( 3);
BOOST_CHECK( ! coro);
@@ -298,7 +298,7 @@ void test_arg_string()
{
value2 = "";
coro::push_coroutine< std::string > coro( f7);
coro::coroutine< std::string >::push_type coro( f7);
BOOST_CHECK( coro);
coro( std::string("abc") );
BOOST_CHECK( ! coro);
@@ -309,7 +309,7 @@ void test_fp()
{
value4 = 0;
coro::push_coroutine< boost::tuple< double, double > > coro( f8);
coro::coroutine< boost::tuple< double, double > >::push_type coro( f8);
BOOST_CHECK( coro);
coro( boost::make_tuple( 7.35, 3.14) );
BOOST_CHECK( coro);
@@ -326,7 +326,7 @@ void test_ptr()
value5 = 0;
int a = 3;
coro::push_coroutine< int * > coro( f9);
coro::coroutine< int * >::push_type coro( f9);
BOOST_CHECK( coro);
coro( & a);
BOOST_CHECK( ! coro);
@@ -338,7 +338,7 @@ void test_const_ptr()
value5 = 0;
int a = 3;
coro::push_coroutine< int const* > coro( f91);
coro::coroutine< int const* >::push_type coro( f91);
BOOST_CHECK( coro);
coro( & a);
BOOST_CHECK( ! coro);
@@ -350,7 +350,7 @@ void test_ref()
value5 = 0;
int a = 3;
coro::push_coroutine< int & > coro( f10);
coro::coroutine< int & >::push_type coro( f10);
BOOST_CHECK( coro);
coro( a);
BOOST_CHECK( ! coro);
@@ -362,7 +362,7 @@ void test_const_ref()
value5 = 0;
int a = 3;
coro::push_coroutine< int const& > coro( f101);
coro::coroutine< int const& >::push_type coro( f101);
BOOST_CHECK( coro);
coro( a);
BOOST_CHECK( ! coro);
@@ -378,7 +378,7 @@ void test_tuple()
boost::tuple< int, int > tpl( a, b);
BOOST_CHECK_EQUAL( a, tpl.get< 0 >() );
BOOST_CHECK_EQUAL( b, tpl.get< 1 >() );
coro::push_coroutine< boost::tuple< int, int > > coro( f11);
coro::coroutine< boost::tuple< int, int > >::push_type coro( f11);
BOOST_CHECK( coro);
coro( tpl);
BOOST_CHECK( ! coro);
@@ -390,7 +390,7 @@ void test_unwind()
{
value1 = 0;
{
coro::push_coroutine< void > coro( f12);
coro::coroutine< void >::push_type coro( f12);
BOOST_CHECK( coro);
BOOST_CHECK_EQUAL( ( int) 0, value1);
coro();
@@ -406,7 +406,7 @@ void test_no_unwind()
{
value1 = 0;
{
coro::push_coroutine< void > coro(
coro::coroutine< void >::push_type coro(
f12,
coro::attributes(
coro::stack_allocator::default_stacksize(),
@@ -428,7 +428,7 @@ void test_exceptions()
std::runtime_error ex("abc");
try
{
coro::push_coroutine< void > coro( boost::bind( f14< std::runtime_error >, _1, ex) );
coro::coroutine< void >::push_type coro( boost::bind( f14< std::runtime_error >, _1, ex) );
BOOST_CHECK( coro);
coro();
BOOST_CHECK( ! coro);
@@ -447,7 +447,7 @@ void test_output_iterator()
{
{
std::vector< int > vec;
coro::pull_coroutine< int > coro( f16);
coro::coroutine< int >::pull_type coro( f16);
BOOST_FOREACH( int i, coro)
{ vec.push_back( i); }
BOOST_CHECK_EQUAL( ( std::size_t)5, vec.size() );
@@ -459,10 +459,10 @@ void test_output_iterator()
}
{
std::vector< int > vec;
coro::pull_coroutine< int > coro( f16);
coro::pull_coroutine< int >::iterator e = boost::end( coro);
coro::coroutine< int >::pull_type coro( f16);
coro::coroutine< int >::pull_type::iterator e = boost::end( coro);
for (
coro::pull_coroutine< int >::iterator i = boost::begin( coro);
coro::coroutine< int >::pull_type::iterator i = boost::begin( coro);
i != e; ++i)
{ vec.push_back( * i); }
BOOST_CHECK_EQUAL( ( std::size_t)5, vec.size() );
@@ -479,10 +479,10 @@ void test_output_iterator()
vec_in.push_back( & i2);
vec_in.push_back( & i3);
std::vector< const int* > vec_out;
coro::pull_coroutine< const int* > coro( boost::bind( f19, _1, boost::ref( vec_in) ) );
coro::pull_coroutine< const int* >::const_iterator e = boost::const_end( coro);
coro::coroutine< const int* >::pull_type coro( boost::bind( f19, _1, boost::ref( vec_in) ) );
coro::coroutine< const int* >::pull_type::const_iterator e = boost::const_end( coro);
for (
coro::pull_coroutine< const int* >::const_iterator i = boost::const_begin( coro);
coro::coroutine< const int* >::pull_type::const_iterator i = boost::const_begin( coro);
i != e; ++i)
{ vec_out.push_back( * i); }
BOOST_CHECK_EQUAL( ( std::size_t)3, vec_out.size() );
@@ -496,10 +496,10 @@ void test_input_iterator()
{
int counter = 0;
std::vector< int > vec;
coro::push_coroutine< int > coro(
coro::coroutine< int >::push_type coro(
boost::bind( f17, _1, boost::ref( vec) ) );
coro::push_coroutine< int >::iterator e( boost::end( coro) );
for ( coro::push_coroutine< int >::iterator i( boost::begin( coro) );
coro::coroutine< int >::push_type::iterator e( boost::end( coro) );
for ( coro::coroutine< int >::push_type::iterator i( boost::begin( coro) );
i != e; ++i)
{
i = ++counter;