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

@@ -11,8 +11,8 @@
#include <boost/coroutine/all.hpp>
#ifdef BOOST_COROUTINES_UNIDIRECT
typedef boost::coroutines::pull_coroutine< void > pull_coro_t;
typedef boost::coroutines::push_coroutine< void > push_coro_t;
typedef boost::coroutines::coroutine< void >::pull_type pull_coro_t;
typedef boost::coroutines::coroutine< void >::push_type push_coro_t;
void echo( pull_coro_t & c, int i)
{

View File

@@ -25,19 +25,19 @@ void echoSSE( int i)
std::cout << v32[3];
}
void echo( boost::coroutines::push_coroutine< void > & c, int i)
void echo( boost::coroutines::coroutine< void >::push_type & c, int i)
{
std::cout << i << ":";
echoSSE(i);
c();
}
void runit( boost::coroutines::push_coroutine< void > & ca)
void runit( boost::coroutines::coroutine< void >::push_type & ca)
{
std::cout << "started! ";
for ( int i = 0; i < 10; ++i)
{
boost::coroutines::pull_coroutine< void > c( boost::bind( echo, _1, i) );
boost::coroutines::coroutine< void >::pull_type c( boost::bind( echo, _1, i) );
while ( c)
c();
ca();
@@ -47,7 +47,7 @@ void runit( boost::coroutines::push_coroutine< void > & ca)
int main( int argc, char * argv[])
{
{
boost::coroutines::pull_coroutine< void > c( runit);
boost::coroutines::coroutine< void >::pull_type c( runit);
while ( c) {
std::cout << "-";
c();

View File

@@ -11,9 +11,11 @@
#include <boost/coroutine/all.hpp>
#ifdef BOOST_COROUTINES_UNIDIRECT
void fibonacci( boost::coroutines::push_coroutine< int > & c)
void fibonacci( boost::coroutines::coroutine< int >::push_type & c)
{
int first = 1, second = 1;
c( first);
c( second);
while ( true)
{
int third = first + second;
@@ -25,9 +27,9 @@ void fibonacci( boost::coroutines::push_coroutine< int > & c)
int main()
{
boost::coroutines::pull_coroutine< int > c( fibonacci);
boost::coroutines::coroutine< int >::pull_type c( fibonacci);
boost::range_iterator<
boost::coroutines::pull_coroutine< int >
boost::coroutines::coroutine< int >::pull_type
>::type it( boost::begin( c) );
for ( int i = 0; i < 10; ++i)
{
@@ -43,6 +45,8 @@ int main()
void fibonacci( boost::coroutines::coroutine< void( int) > & c)
{
int first = 1, second = 1;
c( first);
c( second);
while ( true)
{
int third = first + second;

View File

@@ -11,7 +11,7 @@
#include <boost/coroutine/all.hpp>
#ifdef BOOST_COROUTINES_UNIDIRECT
void first( boost::coroutines::push_coroutine< void > & c)
void first( boost::coroutines::coroutine< void >::push_type & c)
{
std::cout << "started first! ";
for ( int i = 0; i < 10; ++i)
@@ -21,7 +21,7 @@ void first( boost::coroutines::push_coroutine< void > & c)
}
}
void second( boost::coroutines::push_coroutine< void > & c)
void second( boost::coroutines::coroutine< void >::push_type & c)
{
std::cout << "started second! ";
for ( int i = 0; i < 10; ++i)
@@ -34,8 +34,8 @@ void second( boost::coroutines::push_coroutine< void > & c)
int main( int argc, char * argv[])
{
{
boost::coroutines::pull_coroutine< void > c1( boost::bind( first, _1) );
boost::coroutines::pull_coroutine< void > c2( boost::bind( second, _1) );
boost::coroutines::coroutine< void >::pull_type c1( boost::bind( first, _1) );
boost::coroutines::coroutine< void >::pull_type c2( boost::bind( second, _1) );
while ( c1 && c2) {
c1();
std::cout << " ";

View File

@@ -13,7 +13,7 @@
#include <boost/coroutine/all.hpp>
#ifdef BOOST_COROUTINES_UNIDIRECT
void power( boost::coroutines::push_coroutine< int > & c, int number, int exponent)
void power( boost::coroutines::coroutine< int >::push_type & c, int number, int exponent)
{
int counter = 0;
int result = 1;
@@ -28,16 +28,16 @@ int main()
{
{
std::cout << "using range functions" << std::endl;
boost::coroutines::pull_coroutine< int > c( boost::bind( power, _1, 2, 8) );
boost::coroutines::pull_coroutine< int >::iterator e( boost::end( c) );
for ( boost::coroutines::pull_coroutine< int >::iterator i( boost::begin( c) );
boost::coroutines::coroutine< int >::pull_type c( boost::bind( power, _1, 2, 8) );
boost::coroutines::coroutine< int >::pull_type::iterator e( boost::end( c) );
for ( boost::coroutines::coroutine< int >::pull_type::iterator i( boost::begin( c) );
i != e; ++i)
std::cout << * i << " ";
}
{
std::cout << "\nusing BOOST_FOREACH" << std::endl;
boost::coroutines::pull_coroutine< int > c( boost::bind( power, _1, 2, 8) );
boost::coroutines::coroutine< int >::pull_type c( boost::bind( power, _1, 2, 8) );
BOOST_FOREACH( int i, c)
{ std::cout << i << " "; }
}

View File

@@ -50,10 +50,10 @@ std::pair< node::ptr_t, node::ptr_t > create_diff_trees()
}
#ifdef BOOST_COROUTINES_UNIDIRECT
bool match_trees( boost::coroutines::pull_coroutine< leaf & > & c1,
boost::coroutines::pull_coroutine< leaf & > & c2)
bool match_trees( boost::coroutines::coroutine< leaf & >::pull_type & c1,
boost::coroutines::coroutine< leaf & >::pull_type & c2)
{
typedef boost::range_iterator< boost::coroutines::pull_coroutine< leaf & > >::type iterator_t;
typedef boost::range_iterator< boost::coroutines::coroutine< leaf & >::pull_type >::type iterator_t;
iterator_t i1( boost::begin( c1) );
iterator_t e1( boost::end( c1) );
iterator_t i2( boost::begin( c2) );
@@ -64,15 +64,15 @@ int main()
{
{
std::pair< node::ptr_t, node::ptr_t > pt = create_eq_trees();
boost::coroutines::pull_coroutine< leaf & > te1( boost::bind( enumerate_leafs, _1, pt.first) );
boost::coroutines::pull_coroutine< leaf & > te2( boost::bind( enumerate_leafs, _1, pt.second) );
boost::coroutines::coroutine< leaf & >::pull_type te1( boost::bind( enumerate_leafs, _1, pt.first) );
boost::coroutines::coroutine< leaf & >::pull_type te2( boost::bind( enumerate_leafs, _1, pt.second) );
bool result = match_trees( te1, te2);
std::cout << std::boolalpha << "eq. trees matched == " << result << std::endl;
}
{
std::pair< node::ptr_t, node::ptr_t > pt = create_diff_trees();
boost::coroutines::pull_coroutine< leaf & > te1( boost::bind( enumerate_leafs, _1, pt.first) );
boost::coroutines::pull_coroutine< leaf & > te2( boost::bind( enumerate_leafs, _1, pt.second) );
boost::coroutines::coroutine< leaf & >::pull_type te1( boost::bind( enumerate_leafs, _1, pt.first) );
boost::coroutines::coroutine< leaf & >::pull_type te2( boost::bind( enumerate_leafs, _1, pt.second) );
bool result = match_trees( te1, te2);
std::cout << std::boolalpha << "diff. trees matched == " << result << std::endl;
}

View File

@@ -32,7 +32,7 @@ void bar( int i)
}
#ifdef BOOST_COROUTINES_UNIDIRECT
void foo( boost::coroutines::pull_coroutine< void > & c)
void foo( boost::coroutines::coroutine< void >::pull_type & c)
{
bar( count);
c();
@@ -41,7 +41,7 @@ void foo( boost::coroutines::pull_coroutine< void > & c)
void thread_fn()
{
{
boost::coroutines::push_coroutine< void > c( foo);
boost::coroutines::coroutine< void >::push_type c( foo);
c();
}
}

View File

@@ -95,10 +95,10 @@ bool operator!=( leaf const& l, leaf const& r)
class tree_visitor : public visitor
{
private:
boost::coroutines::push_coroutine< leaf & > & c_;
boost::coroutines::coroutine< leaf & >::push_type & c_;
public:
tree_visitor( boost::coroutines::push_coroutine< leaf & > & c) :
tree_visitor( boost::coroutines::coroutine< leaf & >::push_type & c) :
c_( c)
{}
@@ -112,7 +112,7 @@ public:
{ c_( l); }
};
void enumerate_leafs( boost::coroutines::push_coroutine< leaf & > & c, node::ptr_t root)
void enumerate_leafs( boost::coroutines::coroutine< leaf & >::push_type & c, node::ptr_t root)
{
tree_visitor v( c);
root->accept( v);

View File

@@ -17,7 +17,7 @@ struct X : private boost::noncopyable
~X() { std::cout << "~X()" << std::endl; }
};
void fn( boost::coroutines::push_coroutine< void > & c)
void fn( boost::coroutines::coroutine< void >::push_type & c)
{
X x;
int i = 0;
@@ -31,7 +31,7 @@ void fn( boost::coroutines::push_coroutine< void > & c)
int main( int argc, char * argv[])
{
{
boost::coroutines::pull_coroutine< void > c( fn);
boost::coroutines::coroutine< void >::pull_type c( fn);
for ( int k = 0; k < 3; ++k)
{
c();