mirror of
https://github.com/boostorg/coroutine.git
synced 2026-01-31 08:02:18 +00:00
coroutine: support for segmented stacks added
[SVN r82840]
This commit is contained in:
@@ -7,14 +7,10 @@
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/range.hpp>
|
||||
#include <boost/coroutine/all.hpp>
|
||||
|
||||
typedef boost::coroutines::coroutine< int() > coro_t;
|
||||
typedef boost::range_iterator< coro_t >::type iterator_t;
|
||||
|
||||
void fibonacci( coro_t::caller_type & c)
|
||||
void fibonacci( boost::coroutines::coroutine< void( int) > & c)
|
||||
{
|
||||
int first = 1, second = 1;
|
||||
while ( true)
|
||||
@@ -28,9 +24,10 @@ void fibonacci( coro_t::caller_type & c)
|
||||
|
||||
int main()
|
||||
{
|
||||
coro_t c( fibonacci);
|
||||
iterator_t it( boost::begin( c) );
|
||||
BOOST_ASSERT( boost::end( c) != it);
|
||||
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 << " ";
|
||||
@@ -41,3 +38,35 @@ 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