Boost logo

Boost :

Subject: Re: [boost] [coroutine] new versions
From: Vicente J. Botet Escriba (vicente.botet_at_[hidden])
Date: 2012-10-05 15:27:49


Le 05/10/12 17:22, Oliver Kowalke a écrit :
> I've uploaded two re-factored versions - I think most of the
> suggestions from the review are implemented (namespace is not
> corrected and documentation not updated yet).
>
> 1.) http://ok73.ok.funpic.de/boost-coroutine-self.zip
> 2.) http://ok73.ok.funpic.de/boost-coroutine-coro.zip
>
> Version 1) requires that coroutine-fn has only one argument ==
> coroutine<>::self_t. Other arguments are accessed via
> coroutine<>::self_t::get< int >() and results via coroutine<>::get().
> interface provides input/output iterators.
>
> typedef coroutine< int( int, int> > coro_t;
> int fn( coro_t::self_t & c) {
> int x = c.get< 0 >();
> int y = c.get< 1 >();
> c.yield( x +y);
> ...
> }
> coro_t coro( fn);
> int res = c( 3, 7).get();
>
>
> Version 2) requires that coroutine-fn has only one argument too ==
> coroutine<> with inverted signature. Other arguments are access via
> coroutine<>::get().
> interface provides input/output iterators.
>
> typedef coroutine< int( int, int> > coro_t;
> int fn( coroutine< tuple< int, int >( int) & c) {
> int x = c.get().get< 0 >();
> int y = c.get().get< 1 >();
> c( x +y);
> ...
> }
> coro_t coro( fn);
> int res = c( 3, 7).get();
>
> Both implementations are not optimized - I think we should get a small
> and clean interface first.
> Comments?
The single difference between both interfaces is that with fist the
return is obtained using yield, while in the second is using the
operator(). I prefer to use yield to return a result and the call
operator to call to a coroutine. It is not enough clear to me what are
the advantages of having a inversed coroutine as parameter.

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);
     ...
}

Best,
Vicente


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