Boost logo

Boost :

From: Maksym Motornyy (mmotorny_at_[hidden])
Date: 2005-06-03 05:53:25


> I'm interested in implement and have it.

I have to prototypes now. First uses Simon Tatham's trick with case
statement. Generator code looks as follow:

class simple_generator: public coroutine
{
public:
     simple_generator( int j )
         : i( j )
     {
     }

     BEGIN_COROUTINE( int )
         for ( ; i < 10; ++i )
         {
             YIELD( i )
         }
         YIELD( -1 )
     END_COROUTINE

private:
     int i;
};

Second uses Win32 fibers:

class simple_generator
     : public coroutine< simple_generator, int >
{
public:
     simple_generator( int j )
         : j( j )
     {
     }

     void execute()
     {
         for ( int i = j; i < 10; ++i )
             yield( i );
         yield( -1 );
     }

private:
     int j;
};

Both being used in this code:

void main()
{
     simple_generator g( 8 );
     while ( true )
     {
         int result = g();
         if ( result < 0 )
             break;
         cout << result << " ";
     }
}

produce output "8 9 ".

Is anyone interested in details and further discussion?

Sincerely,
Maksym.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk