mirror of
https://github.com/boostorg/coroutine.git
synced 2026-02-10 11:22:32 +00:00
coroutine: activate new interface V2
[SVN r84428]
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user