Boost logo

Boost :

Subject: Re: [boost] [coroutine] new versions
From: Oliver Kowalke (oliver.kowalke_at_[hidden])
Date: 2012-10-05 15:46:02


Am 05.10.2012 21:27, schrieb Vicente J. Botet Escriba:
> The single difference between both interfaces is that with fist the
> return is obtained using yield, while in the second is using the
> operator().

the main difference between version 1 and 2 is that self_t is not a
coroutine<> it is a different type.
Version 2 was suggested by Giovanni and Eugene - especially Eugene has
provided an example demonstrating the benefit of version 2:

void player(coroutine<move(move)> opponent, move his, board brd) {
     while( !brd.is_mate() ) {
         brd.opponent_move(his);
         move mine = ...;
         brd.my_move(mine);
         his = opponent(mine);
     }
}

void white(coroutine<move(move)> opponent) {
     board brd(WHITE);
     move mine = ...;
     brd.my_move(mine);
     his = opponent(mine);
     player(opponent, his, board);
}

void black(coroutine<move(move)> opponent, move his) {
     board brd(BLACK);
     player(opponent, his, brd);
}

void play() {
     coroutine<move(move)> b(black);
     white(b);
}

> I prefer to use yield to return a result and the call operator to call
> to a coroutine.
because slef_t is not of type coroutine<> I expressed the context jump
function as 'yield()' instead of operator()

> It is not enough clear to me what are the advantages of having a
> inversed coroutine as parameter.
If you use symmetric coroutines - see example above

>
> Anyway, maybe the use of the get accessor can be made more readable
> without effort using tags
>
> struct a{};
> struct b{};
> typedef coroutine< int( tagged<int, a>, tagged<int,b> > > coro_t;
> int fn( coro_t::self_t & c) {
> int x = c.get< a >();
> int y = c.get< b >();
> c.yield( x +y);
> ...
> }
>
does boost.tuple provide such a facility?

regards,
Oliver


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