Boost logo

Boost :

Subject: Re: [boost] [coroutine] new location
From: Oliver Kowalke (oliver.kowalke_at_[hidden])
Date: 2012-09-05 16:33:26


Hi,

Am 05.09.2012 21:50, schrieb Christopher Kormanyos:
> The code below is designed to run indefinitely with
> one coroutine. I have, however, used one integer parameter
> to the subroutine f(). The integer parameter is, however,
> not needed. Yet I can not seem to remove the integer parameter
> and get the sample to compile.
>
> Can I remove the integer parameter?
yes
> If so, how should it be coded?
This version compiles for me:

#include <iostream>
#include <boost/coroutine/all.hpp>
#include <boost/bind.hpp>

typedef boost::coro::coroutine< void() > coro_t;

void f(coro_t::self_t & self) // 2nd. arg of type int removed
{
   for(;;)
   {
     std::cout << "In coroutine" << std::endl;
     self.yield();
   }
}

int main(int, char**)
{
   coro_t c( boost::bind(f, _1) );

   for ( ;; )
   {
     std::cout << "In main" << std::endl;
     c();
   }
}

but this second version (binding the 2nd parameter) works for me too:

#include <iostream>
#include <boost/coroutine/all.hpp>
#include <boost/bind.hpp>

typedef boost::coro::coroutine< void() > coro_t;

void f(coro_t::self_t & self, int i)
{
   for(;;)
   {
     std::cout << "In coroutine, i == " << i << std::endl;
     self.yield();
   }
}

int main(int, char**)
{
   coro_t c( boost::bind(f, _1, 1000) );

   for ( ;; )
   {
     std::cout << "In main" << std::endl;
     c();
   }
}

hope I could help

regards,
Oliver


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