coroutine: activate new interface V2

[SVN r84428]
This commit is contained in:
Oliver Kowalke
2013-05-22 20:15:43 +00:00
parent bcae158775
commit ce1270c353
25 changed files with 5903 additions and 179 deletions

View File

@@ -12,6 +12,41 @@
#include <boost/range.hpp>
#include <boost/coroutine/all.hpp>
#ifdef BOOST_COROUTINES_V2
void power( boost::coroutines::push_coroutine< int > & 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;
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) );
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_FOREACH( int i, c)
{ std::cout << i << " "; }
}
std::cout << "\nDone" << std::endl;
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;
@@ -48,45 +83,4 @@ int main()
return EXIT_SUCCESS;
}
#if 0
int main()
{
{
std::cout << "using range functions" << std::endl;
boost::coroutines::coroutine< int() > c(
[&]( boost::coroutines::coroutine< void( int) > &c) {
int counter = 0;
int result = 1;
while ( counter++ < 8)
{
result = result * 2;
c( result);
}
});
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;
boost::coroutines::coroutine< int() > c(
[&]( boost::coroutines::coroutine< void( int) > &c) {
int counter = 0;
int result = 1;
while ( counter++ < 8)
{
result = result * 2;
c( result);
}
});
for ( int i : c) {
std::cout << i << " ";
}
}
std::cout << "\nDone" << std::endl;
return EXIT_SUCCESS;
}
#endif