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

@@ -10,7 +10,8 @@
#include <boost/range.hpp>
#include <boost/coroutine/all.hpp>
void fibonacci( boost::coroutines::coroutine< void( int) > & c)
#ifdef BOOST_COROUTINES_V2
void fibonacci( boost::coroutines::push_coroutine< int > & c)
{
int first = 1, second = 1;
while ( true)
@@ -22,6 +23,35 @@ void fibonacci( boost::coroutines::coroutine< void( int) > & c)
}
}
int main()
{
boost::coroutines::pull_coroutine< int > c( fibonacci);
boost::range_iterator<
boost::coroutines::pull_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;
}
#else
void fibonacci( boost::coroutines::coroutine< void( int) > & c)
{
int first = 1, second = 1;
while ( true)
{
int third = first + second;
first = second;
second = third;
c( third);
}
}
int main()
{
boost::coroutines::coroutine< int() > c( fibonacci);
@@ -38,35 +68,4 @@ int main()
return EXIT_SUCCESS;
}
// C++11
#if 0
int main()
{
boost::coroutines::coroutine< int() > c(
[&]( boost::coroutines::coroutine< void( int) > & c) {
int first = 1, second = 1;
while ( true)
{
int third = first + second;
first = second;
second = third;
c( third);
}
});
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