coroutine: remove deprecated interface

[SVN r86521]
This commit is contained in:
Oliver Kowalke
2013-10-30 08:23:09 +00:00
parent 03acada249
commit e5120a4b71
38 changed files with 3068 additions and 9220 deletions

View File

@@ -75,3 +75,7 @@ exe layout
exe chaining
: chaining.cpp
;
exe exception
: exception.cpp
;

View File

@@ -10,7 +10,6 @@
#include <boost/bind.hpp>
#include <boost/coroutine/all.hpp>
#ifdef BOOST_COROUTINES_UNIDIRECT
typedef boost::coroutines::coroutine< void >::pull_type pull_coro_t;
typedef boost::coroutines::coroutine< void >::push_type push_coro_t;
@@ -46,39 +45,3 @@ int main( int argc, char * argv[])
return EXIT_SUCCESS;
}
#else
typedef boost::coroutines::coroutine< void() > coro_t;
void echo( coro_t & ca, int i)
{
std::cout << i;
ca();
}
void runit( coro_t & ca)
{
std::cout << "started! ";
for ( int i = 0; i < 10; ++i)
{
coro_t c( boost::bind( echo, _1, i) );
while ( c)
c();
ca();
}
}
int main( int argc, char * argv[])
{
{
coro_t c( runit);
while ( c) {
std::cout << "-";
c();
}
}
std::cout << "\nDone" << std::endl;
return EXIT_SUCCESS;
}
#endif

View File

@@ -0,0 +1,52 @@
// Copyright Oliver Kowalke 2009.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include <cstdlib>
#include <iostream>
#include <stdexcept>
#include <string>
#include <boost/bind.hpp>
#include <boost/coroutine/all.hpp>
#include <boost/throw_exception.hpp>
typedef boost::coroutines::coroutine< int >::pull_type pull_coro_t;
typedef boost::coroutines::coroutine< int >::push_type push_coro_t;
struct my_exception : public std::runtime_error
{
my_exception( std::string const& str) :
std::runtime_error( str)
{}
};
void echo( push_coro_t & sink, int j)
{
for ( int i = 0; i < j; ++i)
{
if ( i == 5) boost::throw_exception( my_exception("abc") );
sink( i);
}
}
int main( int argc, char * argv[])
{
pull_coro_t source( boost::bind( echo, _1, 10) );
try
{
while ( source)
{
std::cout << source.get() << std::endl;
source();
}
}
catch ( my_exception const& ex)
{ std::cout << "exception: " << ex.what() << std::endl; }
std::cout << "\nDone" << std::endl;
return EXIT_SUCCESS;
}

View File

@@ -10,7 +10,6 @@
#include <boost/range.hpp>
#include <boost/coroutine/all.hpp>
#ifdef BOOST_COROUTINES_UNIDIRECT
void fibonacci( boost::coroutines::coroutine< int >::push_type & sink)
{
int first = 1, second = 1;
@@ -41,35 +40,3 @@ int main()
return EXIT_SUCCESS;
}
#else
void fibonacci( boost::coroutines::coroutine< void( int) > & c)
{
int first = 1, second = 1;
c( first);
c( second);
while ( true)
{
int third = first + second;
first = second;
second = third;
c( third);
}
}
int main()
{
boost::coroutines::coroutine< int() > c( fibonacci);
boost::range_iterator<
boost::coroutines::coroutine< int() >
>::type it( boost::begin( c) );
for ( int i = 0; i < 10; ++i)
{
std::cout << * it << " ";
++it;
}
std::cout << "\nDone" << std::endl;
return EXIT_SUCCESS;
}
#endif

View File

@@ -10,7 +10,6 @@
#include <boost/bind.hpp>
#include <boost/coroutine/all.hpp>
#ifdef BOOST_COROUTINES_UNIDIRECT
void first( boost::coroutines::coroutine< void >::push_type & sink)
{
std::cout << "started first! ";
@@ -48,44 +47,3 @@ int main( int argc, char * argv[])
return EXIT_SUCCESS;
}
#else
typedef boost::coroutines::coroutine< void() > coroutine_t;
void first( coroutine_t::caller_type & self)
{
std::cout << "started first! ";
for ( int i = 0; i < 10; ++i)
{
self();
std::cout << "a" << i;
}
}
void second( coroutine_t::caller_type & self)
{
std::cout << "started second! ";
for ( int i = 0; i < 10; ++i)
{
self();
std::cout << "b" << i;
}
}
int main( int argc, char * argv[])
{
{
coroutine_t c1( boost::bind( first, _1) );
coroutine_t c2( boost::bind( second, _1) );
while ( c1 && c2) {
c1();
std::cout << " ";
c2();
std::cout << " ";
}
}
std::cout << "\nDone" << std::endl;
return EXIT_SUCCESS;
}
#endif

View File

@@ -12,7 +12,6 @@
#include <boost/range.hpp>
#include <boost/coroutine/all.hpp>
#ifdef BOOST_COROUTINES_UNIDIRECT
void power( boost::coroutines::coroutine< int >::push_type & sink, int number, int exponent)
{
int counter = 0;
@@ -46,41 +45,3 @@ int main()
return EXIT_SUCCESS;
}
#else
typedef boost::coroutines::coroutine< int() > coro1_t;
typedef boost::coroutines::coroutine< void( int) > coro2_t;
typedef boost::range_iterator< coro1_t >::type iterator_t;
void power( coro2_t & c, int number, int exponent)
{
int counter = 0;
int result = 1;
while ( counter++ < exponent)
{
result = result * number;
c( result);
}
}
int main()
{
{
std::cout << "using range functions" << std::endl;
coro1_t c( boost::bind( power, _1, 2, 8) );
iterator_t e( boost::end( c) );
for ( iterator_t i( boost::begin( c) ); i != e; ++i)
std::cout << * i << " ";
}
{
std::cout << "\nusing BOOST_FOREACH" << std::endl;
coro1_t c( boost::bind( power, _1, 2, 8) );
BOOST_FOREACH( int i, c)
{ std::cout << i << " "; }
}
std::cout << "\nDone" << std::endl;
return EXIT_SUCCESS;
}
#endif

View File

@@ -35,7 +35,6 @@ void bar( int i)
}
}
#ifdef BOOST_COROUTINES_UNIDIRECT
void foo( boost::coroutines::coroutine< void >::pull_type & source)
{
bar( count);
@@ -49,23 +48,6 @@ void thread_fn()
sink();
}
}
#else
typedef boost::coroutines::coroutine< void() > coro_t;
void foo( coro_t & c)
{
bar( count);
c();
}
void thread_fn()
{
{
coro_t c( foo);
c();
}
}
#endif
int main( int argc, char * argv[])
{

View File

@@ -91,7 +91,6 @@ inline
bool operator!=( leaf const& l, leaf const& r)
{ return l.value != r.value; }
#ifdef BOOST_COROUTINES_UNIDIRECT
class tree_visitor : public visitor
{
private:
@@ -117,35 +116,6 @@ void enumerate_leafs( boost::coroutines::coroutine< leaf & >::push_type & c, nod
tree_visitor v( c);
root->accept( v);
}
#else
typedef boost::coroutines::coroutine< leaf&() > coro_t;
class tree_visitor : public visitor
{
private:
coro_t::caller_type & c_;
public:
tree_visitor( coro_t::caller_type & c) :
c_( c)
{}
void visit( branch & b)
{
if ( b.left) b.left->accept( * this);
if ( b.right) b.right->accept( * this);
}
void visit( leaf & l)
{ c_( l); }
};
void enumerate_leafs( coro_t::caller_type & c, node::ptr_t root)
{
tree_visitor v( c);
root->accept( v);
}
#endif
# if defined(BOOST_MSVC)
# pragma warning(pop)

View File

@@ -10,7 +10,6 @@
#include <boost/bind.hpp>
#include <boost/coroutine/all.hpp>
#ifdef BOOST_COROUTINES_UNIDIRECT
struct X : private boost::noncopyable
{
X() { std::cout << "X()" << std::endl; }
@@ -43,39 +42,3 @@ int main( int argc, char * argv[])
return EXIT_SUCCESS;
}
#else
typedef boost::coroutines::coroutine< void() > coro_t;
struct X : private boost::noncopyable
{
X() { std::cout << "X()" << std::endl; }
~X() { std::cout << "~X()" << std::endl; }
};
void fn( coro_t & ca)
{
X x;
int i = 0;
while ( true)
{
std::cout << "fn() : " << ++i << std::endl;
ca();
}
}
int main( int argc, char * argv[])
{
{
coro_t c( fn);
for ( int k = 0; k < 3; ++k)
{
c();
}
std::cout << "destroying coroutine and unwinding stack" << std::endl;
}
std::cout << "\nDone" << std::endl;
return EXIT_SUCCESS;
}
#endif